Post by dxforth
I'll take objectors seriously when they get rid of WITHIN.
Speaking of which ...
WITHIN may be used to create BETWEEN. The temptation is to write:
: BETWEEN 1+ WITHIN ;
and some implementations do that e.g. Win32Forth. But the proper way is:
: BETWEEN 1+ SWAP WITHIN 0= ;
which has the same characteristics as the implementation I posted earlier.
The formal definition is:
( n1|u1 n2|u2 n3|u3 -- flag )
Perform a comparison of a test value n1|u1 with a lower limit n2|u2 and an upper
limit n3|u3, returning true if either (n2|u2 <= n3|u3 and (n2|u2 <= n1|u1 and
n1|u1 <= n3|u3)) or (n2|u2 > n3|u3 and (n2|u2 < n1|u1 or n1|u1 < n3|u3)) is true,
returning false otherwise. An ambiguous condition exists if n1|u1, n2|u2, and
n3|u3 are not all the same type.
The rationale follows that of A.6.2.2440 WITHIN with the difference the limits are
inclusive. If n2|u2 and n3|u3 are reversed, then the limits become exclusive.
If Forth is about getting more bang for your buck, then these two functions have that.