On Mar 18, 3:49 pm, an...@[EMAIL PROTECTED]
(Anton Ertl)
wrote:
> Bruce McFarling <agil...@[EMAIL PROTECTED]
> writes:
> >Come to think of it, a shorter valid BETWEEN in terms of WITHIN may
> >be:
>
> >[UNDEFINED] (1) [IF] : (1) ; IMMEDIATE
> >[UNDEFINED] NOT [IF] : NOT 0= ;
> >[ELSE] 1 NOT [IF] : NOT 0= ; [THEN]
> >[THEN]
>
> >\ Circular comparison
> >\ BETWEEN is [lower ... value? ... upper]
> >\ If BETWEEN hits the top before upper, it wraps around to the bottom
>
> >: BETWEEN ( value lower upper -- inside? )
> > 1+ SWAP (1) WITHIN NOT ;
> Not particularly short in this form. What's the point of "(1)"?
Its a comment word. When I want to stack comment in the middle of a
word, I use immediate no-ops (1) through (4) and there is a comment
like:
\ (1) ...
.... below.
For me, four words is short. I'm not trying to fit as many as possible
into one block ... if it is blocked, it will be in a pseudo-textfile
block range.
> Anyway, rewriting this without all the ifdefs:
> : between 1+ swap within 0= ;
>
> A few tests I did look good.
>
> Looking at this closely, I see the sequence SWAP WITHIN 0=, which I
> claimed to be equivalent to WITHIN, but I tested it with, e.g.
>
> 3 3 3 within .
> 3 3 3 swap within 0= .
>
> and the results differ; so the equivalence holds only when the bounds
> are different. The reason is that the range covered by WITHIN is the
> empty set when the two bounds are equal; SWAP is a noop in this case,
> so the 0= means that the range of SWAP WITHIN 0= covers all numbers on
> the circle. For defining BETWEEN you need a variant of WITHIN that
> has this property. So I believe that this definition is correct.
>
> Cool. How did you find that?
I was do***enting the various manipulations of BETWEEN for character
testing, and started using the
[lower ... value? ... upper]
comment to show what had happened to the inputs just before BETWEEN
executes... like,
[lower=value?=upper]
[upper+1 ... value? ... lower+1]
etc.
when its duplicated, and it tickled something in my memory on modulus
arithmetic from Number theory ... in modulus arithmatic,
\{[lower...upper]} = {upper(...)lower}, or, IOW,
A member [lower...upper] iff A not member upper(...)lower
and so if they are modulus integers, with WITHIN's semi-closed range,
[lower... value ... upper] = ~{[upper+1... value? ...)lower}
1+ is ( lower upper+1 )
SWAP is ( upper+1 lower )
WITHIN is [upper+1... value? ...)lower
NOT is ~{[upper+1... value? ...)lower}
Having this definition is useful in taking NOT-BETWEEN and trimming
down its footprint when WITHIN is assumed to be the most likely to be
coded efficiently.
: NOT-BETWEEN ( value lower upper -- flag ) \ NOT{ [lower ...
value? ... upper] }
1+ SWAP 1+ BETWEEN ;
.... if BETWEEN is in terms of WITHIN
: NOT-BETWEEN ( value lower upper -- flag ) \ NOT{ [lower ...
value? ... upper] }
1+ SWAP 1+ 1+ SWAP WITHIN NOT ;
-->
: NOT-BETWEEN ( value lower upper -- flag ) \ NOT{ [lower ...
value? ... upper] }
2 1 D+ WITHIN NOT ;


|