RfD: String comparison words version 1 (was version 0)

forth

    Next

  • 1. Forth guy running for President of the USA by Amendment
    And now I have a .com. presidentbyamendment.com Read the Amendment at that URL. Suggestions? Hi folks. Rick Hohensee
  • 2. I want to learn forth but...
    I have three goals... 1) Learn to program 2) Make a program for a portable device like the iPhone, Google Android, the new Palm phone, etc 3) do 1 & 2 sanely, i.e., that is, via a "1X" forth However, there is no 1X forths available for the new wave of phones as far as I can tell. So my options then are say learn Java so I can write something for the google phone. PLEASE help me to avoid learning Java. I would love to write something in forth. I would love to learn forth. Is there any way that makes sense that I can use forth? iphone seems propietary and thus too hard, android shows a little more promise but their reliance on Java is the obstacle, the new palm phone, who knows, but it won't be forth friendly... is there any popular phone/pda that I can use forth with? and, if I do sell out, and go the java route, how much of 1X forth methodology can I apply to java? aka, how do I be a good programmer in a "bad" language (yes, it has its own merits I suppose but I'm sold on the 1X forth approach) any opinions, opportunities, insights, etc would be appreciated -Green

Re: RfD: String comparison words version 1 (was version 0)

Postby Andrew Haley » Thu, 25 Nov 2010 01:30:32 GMT




Okay, but does the standard Forth language really need a string
comparison operator that optimizes this particular case?  Really? ...

Andrew.

Re: RfD: String comparison words version 1 (was version 0)

Postby Bernd Paysan » Thu, 25 Nov 2010 02:07:43 GMT




Hashing the strings first should solve that problem - the hash is different 
even when the prefix is the same.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself!"
 http://www.**--****.com/ ~paysan/

Re: RfD: String comparison words version 1 (was version 0)

Postby Bernd Paysan » Thu, 25 Nov 2010 02:07:43 GMT




Hashing the strings first should solve that problem - the hash is different 
even when the prefix is the same.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself!"
 http://www.**--****.com/ ~paysan/

Re: RfD: String comparison words version 1 (was version 0)

Postby anton » Thu, 25 Nov 2010 02:32:17 GMT

Andrew Haley < XXXX@XXXXX.COM > writes:



I did not introduce STR= in Gforth because of performance
considerations.  Indeed, the implementation of STR= in Gforth is:

: str=  
  compare 0= ;

The value in STR= and STR< is in the better interface.  It is the
analogue of = and <.

If the combination of COMPARE and 0=/0< was the right interface, why
does Forth have =, <, U<, D=, D< etc.?  They could all be replaced
with, say, CMP, UCMP, DCMP combined with 0= and 0<, where CMP compares
two signed cells and returns -1, 0, or 1 depending on the result of
the comparison.

- anton
-- 
M. Anton Ertl   http://www.**--****.com/ 
comp.lang.forth FAQs:  http://www.**--****.com/ 
     New standard:  http://www.**--****.com/ 
   EuroForth 2010:  http://www.**--****.com/ 

Re: RfD: String comparison words version 1 (was version 0)

Postby BruceMcF » Thu, 25 Nov 2010 03:39:02 GMT



Doesn't much of the juggling go away if the underlying factor is
\ S= ( ca1 ca2 u -- flag )
\ * test whether the ( ca1 u ) and ( ca2 u ) are equal

: STR= ( ca1 u1 ca2 u2 -- flag )
   ROT OVER = IF S= ELSE DROP 2DROP FALSE THEN ;

It also gives symmetric substring equality, with even less overhead:

: SS= ( ca1 u1 ca2 u2 -- flag ) ROT MIN S= ;

Assymetric substring testing is also easier with S= as the (possibly
optimized) primitive factor. So I'd rather S= standard and STR= and
SS= (or whatever you want to call it) Comus than STR= standard and S=
and SS= Comus.

Re: RfD: String comparison words version 1 (was version 0)

Postby Andrew Haley » Thu, 25 Nov 2010 04:44:51 GMT





Indeed they could, and on very small systems it might be a good idea.
COMPARE is a compromise to keep the size of the wordset small, and
quite a good one.  This is much the same as the reasoning for
strcmp(), I suppose: C used to be a small language like Forth.

Andrew.


Return to forth

 

Who is online

Users browsing this forum: No registered users and 87 guest