Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logical AND in Forth?

I know the AND word defines binary and... but what defines logical and?

like image 323
Johan Kotlinski Avatar asked Oct 06 '10 14:10

Johan Kotlinski


1 Answers

The same word, AND, is also used for logical and. But the two input values to AND are recommended to be well-formed flags; true and false are represented by two values, bits all set (-1) and bits all unset (0). Other values than these may work as true (as in C), but it may lead to subtle errors.

All comparison operators return well-formed flags, but for instance - does not. The following evaluates to false (0).

7 5 - 7 3 - AND

AND gets bit patterns 100 and 010. The result is 0 (as it does the bitwise and).

References:

  1. Bit Manipulations in Forth, part of Learning Forth Bit by Bit.
  2. Section "A Little Logic" in Chapter 4 of Starting Forth.
like image 91
Peter Mortensen Avatar answered Oct 23 '22 13:10

Peter Mortensen