[retroforth] Re: 'not' not working correctly

  • From: "Ron Aaron" <ron@xxxxxxxxxxx>
  • To: retroforth@xxxxxxxxxxxxx
  • Date: Tue, 25 Jan 2005 08:21:59 -0800 (PST)

On Tue, January 25, 2005 3:12, Charles Childers said:
> After testing several Forths, only one doesn't return "-2" when I do
> "1 not".  The only one that returns "0" is Win32Forth. I found the
> following note on the web:
>
>> Logical NOT
>> NOT reverses the logical state of its operand. If the
>> operand is 0, 1 is returned, else 0 is returned.
>>
>>      !4      /* Returns 0    */
>>      !-4     /* Returns 0    */
>>      !1      /* Returns 0    */
>>      !0      /* Returns 1    */
>
> If this is accurate, not should basically be:
>
>   : not 0 =if 1 ;; then 0 ;
>
> I'll probably keep the binary not in RetroForth 8, but define a
> logical not as part of the code library.

There are two NOT words: one LOGICAL and one BITWISE. You have implemented the
BITWISE one (equiv of -1 XOR ) but your docs say you implemented the LOGICAL
one.  Likewise in your docs for 'and', 'or' and 'xor' you claim LOGICAL but
they are BITWISE.  This must be consistant.

'pforth' also implements NOT as a LOGICAL operator.  The idea is you could do
something like;

failed not if ... then


In any case, you must be consistant in your usage of LOGICAL vs BITWISE and
certainly the docs should strive for accuracy, particularly given their
terseness.

Win32Forth implements bitwise-not as INVERT and logical-not as NOT.  I have
done the same for Reva now.

-- 
My GPG public key is at http://ronware.org/
fingerprint: 8130 734C 69A3 6542 0853  CB42 3ECF 9259 AD29 415D




Other related posts: