I know the AND word defines binary and
... but what defines logical and
?
views:
61answers:
1
+1
A:
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 may lead to subtle errors.
All comparison operators return well-formed flags, but for instance -
does not. This returns false (0):
7 5 - 7 3 - AND
AND
gets bit patterns 100 and 010. The result is 0 (as it does the binary and).
References:
- Bit Manipulations in Forth, part of Learning Forth Bit by Bit.
- Section "A Little Logic" in Chapter 4 of Starting Forth.
Peter Mortensen
2010-10-07 19:47:41
Don't know enough forth to say if this is valid, but the bit patterns 0xFF00 and 0x00FF have bitwise and 0x0000 but logical and True (since both are nonzero)
TokenMacGuy
2010-10-07 19:56:25
@TokenMacGuy: Thanks! It was such an example I was looking for. I have updated the answer.
Peter Mortensen
2010-10-07 20:04:22