home .. forth .. colorforth mail list archive ..

[ColorForth] Equality


If you are comparing against a literal (as it appears you are), then you
can use the "?" macro:

   "n ?" will compile "TEST EAX, n"

: things
  5 eq if 5thing ; then
  11 eq if 11thing ; then
  38 eq if 38thing ; then
  otherthing ;

Notice that if the stack has one item on it going into "things", then
it'll still have that one same item on it going into "5thing" and etc.

Unless I'm completely misunderstanding all this, that is. :-)

On Thu, 20 Jun 2002, Richard Collins wrote:

> I feel like an idiot asking this. But here goes anyway.
> 
> How does one get by without an equals operator. I want to say something like
> this:
> 
> 5 5 eq if 5thing then ;
> 
> I could rearrange it to:
> 
> 5 5 xor if ; then 5thing ;
> 
> But this seems like too much of a fudge, particularily because what I really
> want to do is more like,
> 
> : things
> dup 5 eq if 5thing ; then
> dup 11 eq if 11thing ; then
> dup 38 eq if 38 thing ; then
> drop otherthing ;
> 
> which becomes
> 
> : things
> dup 5 xor if
>     dup 11 xor if
>         dup 38 xor if drop otherthing  ; then 38thing ;
>     then 11thing ;
> then 5thing ;
> 
> Defining eq as
> : eq xor - drop ;
> doesn't work as - doesn't affect the pentiums flags.
> 
> My last resort is to define a new 'if', 'if0' which jumps forward to the
> next 'then' when the zero flag is not set, instead of when it is set, which
> is how 'if' works. This would not be hard, but I can't help but think that
> if it was needed, Chuck would have put it there.
> 
> I'll be grateful for any advice. I suspect I am approaching things from the
> wrong angle.
> 
> Thanks, Richard Collins
> ------------------------
> 
> To Unsubscribe from this list, send mail to Mdaemon@xxxxxxxxxxxxxxxxxx with:
> unsubscribe ColorForth
> as the first and only line within the message body
> Problems   -   List-Admin@xxxxxxxxxxxxxxxxxx
> Main ColorForth site   -   http://www.colorforth.com
> 
> 
> 
------------------------

To Unsubscribe from this list, send mail to Mdaemon@xxxxxxxxxxxxxxxxxx with:
unsubscribe ColorForth
as the first and only line within the message body
Problems   -   List-Admin@xxxxxxxxxxxxxxxxxx
Main ColorForth site   -   http://www.colorforth.com