BETWEEN
  Home FAQ Contact Sign in
comp.lang.forth only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.forth Profile…
 Up
BETWEEN         


Author: Ed
Date: Mar 10, 2008 16:05

WITHIN was meant to replace BETWEEN but it hasn't always
been a comfortable fit.

A characteristic of WITHIN is that the upper limit is not included
in the range. This can lead to obfuscated code e.g.

CHAR a CHAR z 1+ WITHIN

Thus the functionality of BETWEEN is still being used, if not
the word itself. When defined today, it is usually as:

: BETWEEN ( n1|u1 n2|u2 n3|u3 -- flag ) 1+ WITHIN ;

But it is not without problem e.g. it fails when u1 = u3 = MAX-U .
Perhaps not so significant for 32-bit systems as for 16-bit, it is
nevertheless an inconsistency which can catch a programmer
unawares.

Playing with the algorithm for WITHIN (A.6.2.2440) one gets:

: BETWEEN ( n1|u1 n2|u2 n3|u3 -- flag ) OVER - -ROT - U< 0= ;

It seems to work. If anyone finds a problem or knows something
better, let us know. In the meantime, here are several code versions.
Show full article (1.24Kb)
152 Comments
Re: BETWEEN         


Author: Jerry Avins
Date: Mar 10, 2008 20:27

Ed wrote:
> WITHIN was meant to replace BETWEEN but it hasn't always
> been a comfortable fit.

The other way around. WITHIN came first. It may be as nice, but its code
is so snazzy that I find it more esthetically pleasing.
> A characteristic of WITHIN is that the upper limit is not included
> in the range. This can lead to obfuscated code e.g.
>
> CHAR a CHAR z 1+ WITHIN
>
> Thus the functionality of BETWEEN is still being used, if not
> the word itself. When defined today, it is usually as:
>
> : BETWEEN ( n1|u1 n2|u2 n3|u3 -- flag ) 1+ WITHIN ;

Clearly, WITHIN came first in this case.
> But it is not without problem e.g. it fails when u1 = u3 = MAX-U .

It is the comparison operator in the definition that "fails".
Show full article (1.31Kb)
no comments
Re: BETWEEN         


Author: Ed
Date: Mar 11, 2008 16:59

"Jerry Avins" ieee.org> wrote in message news:rIadnSizg9q1YUjanZ2dnUVZ_gWdnZ2d@rcn.net...
> Ed wrote:
>> WITHIN was meant to replace BETWEEN but it hasn't always
>> been a comfortable fit.
>
> The other way around. WITHIN came first. It may be as nice, but its code
> is so snazzy that I find it more esthetically pleasing.

In the version I show, the algorithms are very similar. WITHIN uses
U< whereas BETWEEN uses U<= .

AFAIK, BETWEEN can't be made from WITHIN and vice-versa so
it suggests they're equally primitive. Both seem to have their
applications.
Show full article (1.63Kb)
no comments
Re: BETWEEN         


Author: Coos Haak
Date: Mar 11, 2008 18:02

Op Wed, 12 Mar 2008 10:59:55 +1100 schreef Ed:
> "Jerry Avins" ieee.org> wrote in message news:rIadnSizg9q1YUjanZ2dnUVZ_gWdnZ2d@rcn.net...
>> Ed wrote:
>>> WITHIN was meant to replace BETWEEN but it hasn't always
>>> been a comfortable fit.
>>
>> The other way around. WITHIN came first. It may be as nice, but its code
>> is so snazzy that I find it more esthetically pleasing.
>
> In the version I show, the algorithms are very similar. WITHIN uses
> U< whereas BETWEEN uses U<= .
>
> AFAIK, BETWEEN can't be made from WITHIN and vice-versa so
> it suggests they're equally primitive. Both seem to have their
> applications.
>
Of course:

: BETWEEN 1+ WITHIN ;
: WITHIN 1- BETWEEN ;
Show full article (0.79Kb)
no comments
Re: BETWEEN         


Author: Bruce McFarling
Date: Mar 11, 2008 20:06

On Mar 11, 9:02 pm, Coos Haak wrote:
> Op Wed, 12 Mar 2008 10:59:55 +1100 schreef Ed:
>
>> "Jerry Avins" ieee.org> wrote in messagenews:rIadnSizg9q1YUjanZ2dnUVZ_gWdnZ2d@rcn.net...
>>> Ed wrote:
>>>> WITHIN was meant to replace BETWEEN but it hasn't always
>>>> been a comfortable fit.
>
>>> The other way around. WITHIN came first. It may be as nice, but its code
>>> is so snazzy that I find it more esthetically pleasing.
>
>> In the version I show, the algorithms are very similar. WITHIN uses
>> U< whereas BETWEEN uses U<= .
>
>> AFAIK, BETWEEN can't be made from WITHIN and vice-versa so
>> it suggests they're equally primitive. Both seem to have their
>> applications.
>
> Of course:
> ...
Show full article (1.07Kb)
no comments
Re: BETWEEN         


Author: Jerry Avins
Date: Mar 11, 2008 20:38

Ed wrote:
> "Jerry Avins" ieee.org> wrote in message news:rIadnSizg9q1YUjanZ2dnUVZ_gWdnZ2d@rcn.net...
>> Ed wrote:
>>> WITHIN was meant to replace BETWEEN but it hasn't always
>>> been a comfortable fit.
>> The other way around. WITHIN came first. It may be as nice, but its code
>> is so snazzy that I find it more esthetically pleasing.
>
> In the version I show, the algorithms are very similar. WITHIN uses
> U< whereas BETWEEN uses U<= .
>
> AFAIK, BETWEEN can't be made from WITHIN and vice-versa so
> it suggests they're equally primitive. Both seem to have their
> applications.

?? You show below how to do it with 1+ .
Show full article (2.13Kb)
no comments
Re: BETWEEN         


Author: Elizabeth D Rather
Date: Mar 11, 2008 21:57

Ed wrote:
> "Jerry Avins" ieee.org> wrote in message news:rIadnSizg9q1YUjanZ2dnUVZ_gWdnZ2d@rcn.net...
>> Ed wrote:
>>> WITHIN was meant to replace BETWEEN but it hasn't always
>>> been a comfortable fit.
>> The other way around. WITHIN came first. It may be as nice, but its code
>> is so snazzy that I find it more esthetically pleasing.
>
> In the version I show, the algorithms are very similar. WITHIN uses
> U< whereas BETWEEN uses U<= .
>
> AFAIK, BETWEEN can't be made from WITHIN and vice-versa so
> it suggests they're equally primitive. Both seem to have their
> applications.
>

WITHIN came first *historically*. It handles its arguments as it does
to be consistent with the fact that 0 DO ... LOOP will run n-1 times
(i.e. exclusive at the top end), which made that behavior easy to teach
and remember.
Show full article (1.57Kb)
no comments
Re: BETWEEN         


Author: William James
Date: Mar 12, 2008 02:28

On Mar 11, 10:57 pm, Elizabeth D. Rather forth.com> wrote:
> to be consistent with the fact that 0 DO ... LOOP will run n-1 times

An off-by-one error. It will run n times.
no comments
Re: BETWEEN         


Author: William James
Date: Mar 12, 2008 02:41

On Mar 10, 5:05 pm, "Ed" invalid.com> wrote:
> Playing with the algorithm for WITHIN (A.6.2.2440) one gets:
>
> : BETWEEN ( n1|u1 n2|u2 n3|u3 -- flag ) OVER - -ROT - U< 0= ;

Stuff like this leads one to believe that Forth code is
unreadable, cryptic, unsharable, and unmaintainable.
It's worse than some assembly language I've seen.
Forth needs to become a higher-level language.
20 Comments
Re: BETWEEN         


Author: Jonah Thomas
Date: Mar 12, 2008 04:53

William James yahoo.com> wrote:
> "Ed" invalid.com> wrote:
>
>> Playing with the algorithm for WITHIN (A.6.2.2440) one gets:
>>
>> : BETWEEN ( n1|u1 n2|u2 n3|u3 -- flag ) OVER - -ROT - U< 0= ;
>
> Stuff like this leads one to believe that Forth code is
> unreadable, cryptic, unsharable, and unmaintainable.
> It's worse than some assembly language I've seen.
> Forth needs to become a higher-level language.

What are your standards for readability?

I see six commands, and I understand every one of them. No control
structures. It doesn't get much clearer than that.

The name tells me what it's supposed to do, surrounded by the comments
in the surrounding topic.

What's missing is the test cases. Give us test cases with say the Hayes
convention, and it would be perfect.

n3-n2 n1-n2 U< 0=
Show full article (2.11Kb)
no comments
1 2 3 4 5 6 7 8 9