Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #134657 > unrolled thread

A new DO..LOOP (from 4tH forum)

Started byHans Bezemer <the.beez.speaks@gmail.com>
First post2026-03-13 14:43 +0100
Last post2026-03-15 16:13 +1100
Articles 20 on this page of 31 — 7 participants

Back to article view | Back to comp.lang.forth


Contents

  A new DO..LOOP (from 4tH forum) Hans Bezemer <the.beez.speaks@gmail.com> - 2026-03-13 14:43 +0100
    Re: A new DO..LOOP (from 4tH forum) Paul Rubin <no.email@nospam.invalid> - 2026-03-13 15:05 -0700
      Re: A new DO..LOOP (from 4tH forum) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-14 10:54 +0000
        Re: A new DO..LOOP (from 4tH forum) albert@spenarnc.xs4all.nl - 2026-03-14 15:13 +0100
          Re: A new DO..LOOP (from 4tH forum) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-14 15:34 +0000
            Re: A new DO..LOOP (from 4tH forum) albert@spenarnc.xs4all.nl - 2026-03-15 11:55 +0100
          Re: A new DO..LOOP (from 4tH forum) Paul Rubin <no.email@nospam.invalid> - 2026-03-14 15:57 -0700
            Re: A new DO..LOOP (from 4tH forum) albert@spenarnc.xs4all.nl - 2026-03-15 11:42 +0100
              Re: A new DO..LOOP (from 4tH forum) Paul Rubin <no.email@nospam.invalid> - 2026-03-15 13:27 -0700
          Re: A new DO..LOOP (from 4tH forum) Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-15 09:55 -0500
            Re: A new DO..LOOP (from 4tH forum) Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-15 10:01 -0500
              Re: A new DO..LOOP (from 4tH forum) Hans Bezemer <the.beez.speaks@gmail.com> - 2026-03-15 19:11 +0100
                Re: A new DO..LOOP (from 4tH forum) Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-15 19:36 -0500
                  Re: A new DO..LOOP (from 4tH forum) Hans Bezemer <the.beez.speaks@gmail.com> - 2026-03-16 14:28 +0100
                    Re: A new DO..LOOP (from 4tH forum) Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-16 10:53 -0500
                      Re: A new DO..LOOP (from 4tH forum) Hans Bezemer <the.beez.speaks@gmail.com> - 2026-03-16 19:25 +0100
                      Re: A new DO..LOOP (from 4tH forum) albert@spenarnc.xs4all.nl - 2026-03-16 20:25 +0100
                        Re: A new DO..LOOP (from 4tH forum) Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-16 16:52 -0500
                          Re: A new DO..LOOP (from 4tH forum) Hans Bezemer <the.beez.speaks@gmail.com> - 2026-03-17 14:24 +0100
            Re: A new DO..LOOP (from 4tH forum) albert@spenarnc.xs4all.nl - 2026-03-15 19:07 +0100
              Re: A new DO..LOOP (from 4tH forum) Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-15 18:35 -0500
                Re: A new DO..LOOP (from 4tH forum) albert@spenarnc.xs4all.nl - 2026-03-16 12:26 +0100
                  Re: A new DO..LOOP (from 4tH forum) Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-16 08:20 -0500
                    Re: A new DO..LOOP (from 4tH forum) Hans Bezemer <the.beez.speaks@gmail.com> - 2026-03-16 15:29 +0100
                      Re: A new DO..LOOP (from 4tH forum) albert@spenarnc.xs4all.nl - 2026-03-16 20:07 +0100
                  Re: A new DO..LOOP (from 4tH forum) Hans Bezemer <the.beez.speaks@gmail.com> - 2026-03-16 14:30 +0100
              Re: A new DO..LOOP (from 4tH forum) Gerry Jackson <do-not-use@swldwa.uk> - 2026-03-16 14:42 +0000
                Re: A new DO..LOOP (from 4tH forum) albert@spenarnc.xs4all.nl - 2026-03-16 20:11 +0100
        Re: A new DO..LOOP (from 4tH forum) Hans Bezemer <the.beez.speaks@gmail.com> - 2026-03-14 15:38 +0100
      Re: A new DO..LOOP (from 4tH forum) Hans Bezemer <the.beez.speaks@gmail.com> - 2026-03-14 14:54 +0100
        Re: A new DO..LOOP (from 4tH forum) dxf <dxforth@gmail.com> - 2026-03-15 16:13 +1100

Page 1 of 2  [1] 2  Next page →


#134657 — A new DO..LOOP (from 4tH forum)

FromHans Bezemer <the.beez.speaks@gmail.com>
Date2026-03-13 14:43 +0100
SubjectA new DO..LOOP (from 4tH forum)
Message-ID<nnd$20b3b3c0$0407aa81@c87f832af3cab682>
Hi 4tH-ers!

You know we've been struggling with DO..LOOP since eternity. Chuck 
thought he's rather replace the whole shebang with FOR..NEXT.

For years I've largely avoided DO..LOOP where possible, using 
BEGIN..REPEAT instead.

But now I've encoded it in a few macros - and it works fine (at first 
sight)!

Like DO..LOOP it keeps its parameters on the Return stack, but it allows 
WHILE of EXCEPT to add additional conditions. With the parameters on the 
Return stack, it still requires UNLOOP to exit it, of course.

Also - you feed the parameters like a BASIC FOR..NEXT loop - that is: 
inclusive. It also does NOT enter the loop when parameters are out of 
reach. And you can define a STEP very naturally. In 4tH, you can still 
use I and J.

:macro countup   1+ begin over over >r >r < while ;
:macro countdown 1- begin over over >r >r > while ;
:macro step      r> + r> repeat rdrop rdrop ;

10 30 countup   i . 1 step cr
30 10 countdown i . -1 step cr
10 30 countup   i . i 15 < while 1 step cr

This renders:

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10
10 11 12 13 14 15

Let me know what you think. I'm adding this to the 4pp repository.

Hans Bezemer

[toc] | [next] | [standalone]


#134658

FromPaul Rubin <no.email@nospam.invalid>
Date2026-03-13 15:05 -0700
Message-ID<87fr63e669.fsf@nightsong.com>
In reply to#134657
Hans Bezemer <the.beez.speaks@gmail.com> writes:
> Let me know what you think. I'm adding this to the 4pp repository.

I thought ?DO was supposed to fix the main issues of DO.

[toc] | [prev] | [next] | [standalone]


#134661

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2026-03-14 10:54 +0000
Message-ID<2026Mar14.115416@mips.complang.tuwien.ac.at>
In reply to#134658
Paul Rubin <no.email@nospam.invalid> writes:
>I thought ?DO was supposed to fix the main issues of DO.

?DO is an improvement over DO in many cases, but I found the resulting
standard counted-loop variants unsatisfying, and have worked on
improved counted-loop constructs over the last three decades, even as
recently as 2024 <2024Jan28.131537@mips.complang.tuwien.ac.at>.

You can read the "Counted Loops" Section in the manual of Gforth's
development version (currently unavailable on the web
<https://net2o.de/gforth/>, but hopefully online again soon) and think
about why I introduced the various additional words were introduced.
No other Forth system has picked them up, so maybe other Forth systems
do not consider the standard counted loops as unsatisfying as I do, or
maybe they consider the price in additional words to be too high.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: https://forth-standard.org/
EuroForth 2025 proceedings: http://www.euroforth.org/ef25/papers/

[toc] | [prev] | [next] | [standalone]


#134664

Fromalbert@spenarnc.xs4all.nl
Date2026-03-14 15:13 +0100
Message-ID<nnd$59a32897$2ac4048f@0c7f56827c71a837>
In reply to#134661
In article <2026Mar14.115416@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>Paul Rubin <no.email@nospam.invalid> writes:
>>I thought ?DO was supposed to fix the main issues of DO.
>
>?DO is an improvement over DO in many cases, but I found the resulting
>standard counted-loop variants unsatisfying, and have worked on
>improved counted-loop constructs over the last three decades, even as
>recently as 2024 <2024Jan28.131537@mips.complang.tuwien.ac.at>.
>
>You can read the "Counted Loops" Section in the manual of Gforth's
>development version (currently unavailable on the web
><https://net2o.de/gforth/>, but hopefully online again soon) and think
>about why I introduced the various additional words were introduced.
>No other Forth system has picked them up, so maybe other Forth systems
>do not consider the standard counted loops as unsatisfying as I do, or
>maybe they consider the price in additional words to be too high.

We have painted ourselves in a corner.

I certainly do find DO unsatisfactory. I don't think it can be settled
unless we define the body as a lambda, an anonymous piece of code
that can be executed repeatedly.
The cute trick that DO can be used to handle signed and unsigned indices
at the same time is holding us back.
\ DO ( i1 i2 xt -- ?? )
1 3 { IX . } DO
1 2 3 OK
3 1 { IX . } DO
OK
The idea about +LOOP is also insane. If you have an increment, that must be
defined once and for all.
1 6 2 { IX . } DO[..]
1 3 5 OK
That also fixes decrementing loops:
6 1 -2 { IX . } DO[..]
6 4 2 OK

Note that this construct can be executed or compiled,
in the premise that he distinction between
:NONAME .. ; and [: .. ;]
is also defective.
There is no hope that this can be approved,
because you are actually defining a whole new language.
Merely adding extra words that burdens the memory is not a good
solution.

For now I accept DO DO? for better or for worse.

>
>- anton

Groetjes Albert
-- 
The Chinese government is satisfied with its military superiority over USA.
The next 5 year plan has as primary goal to advance life expectancy
over 80 years, like Western Europe.

[toc] | [prev] | [next] | [standalone]


#134668

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2026-03-14 15:34 +0000
Message-ID<2026Mar14.163425@mips.complang.tuwien.ac.at>
In reply to#134664
albert@spenarnc.xs4all.nl writes:
>We have painted ourselves in a corner.

Speak for yourself.  I am actually pretty happy with the current set
of Gforth's counted-loop words.

>I certainly do find DO unsatisfactory. I don't think it can be settled
>unless we define the body as a lambda, an anonymous piece of code
>that can be executed repeatedly.

Gforth has support for (flat) closures, and they can be useful in some
cases, but for counted loops I don't see any benefit from closures
(even the varant with access to outer locals).

Sure, TRAVERSE-WORDLIST is similar in spirit to a counted loop and we
pass an xt to it (so, in Gforth, you can pass a closure to it); an
alternative to that would have been to have a ?DO-WORDLIST and a
LOOP-WORDLIST, or somesuch; the current entry might have been gotten
with I, and LEAVE would leave the loop, making it unnecessary to pass
a flag to indicate this.

>The cute trick that DO can be used to handle signed and unsigned indices
>at the same time is holding us back.

Speak for yourself.  Gforth has words for signed and for unsigned loop
control parameters:

 +DO  -[DO  -DO
U+DO U-[DO U-DO

Gforth also has

ARRAY>MEM MEM+DO MEM-DO

which factors away the error-prone array handling (especially
beneficial in the MEM-DO case).

>The idea about +LOOP is also insane. If you have an increment, that must be
>defined once and for all.
>1 6 2 { IX . } DO[..]
>1 3 5 OK
>That also fixes decrementing loops:
>6 1 -2 { IX . } DO[..]
>6 4 2 OK

That's certainly the idea behind ARRAY>MEM and MEM+DO and MEM-DO, but
they are designed for dealing with arrays.  Maybe one day I will come
across a usage that will inspire me to design a more general counted
loop with stride.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: https://forth-standard.org/
EuroForth 2025 proceedings: http://www.euroforth.org/ef25/papers/

[toc] | [prev] | [next] | [standalone]


#134675

Fromalbert@spenarnc.xs4all.nl
Date2026-03-15 11:55 +0100
Message-ID<nnd$1c631757$05855d8d@5c165b0c76afafb2>
In reply to#134668
In article <2026Mar14.163425@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>albert@spenarnc.xs4all.nl writes:
>>We have painted ourselves in a corner.
>
>Speak for yourself.  I am actually pretty happy with the current set
>of Gforth's counted-loop words.

The truth is independant whether any one person accept it or not.

DO remains me of Patriot missiles. Invented in the cold war era,
fixed and updated, now ineffective.

<SNIP>

>- anton

Groetjes Albert
-- 
The Chinese government is satisfied with its military superiority over USA.
The next 5 year plan has as primary goal to advance life expectancy
over 80 years, like Western Europe.

[toc] | [prev] | [next] | [standalone]


#134670

FromPaul Rubin <no.email@nospam.invalid>
Date2026-03-14 15:57 -0700
Message-ID<877brednoq.fsf@nightsong.com>
In reply to#134664
albert@spenarnc.xs4all.nl writes:
> I certainly do find DO unsatisfactory. I don't think it can be settled
> unless we define the body as a lambda, an anonymous piece of code
> that can be executed repeatedly.

I now remember doing something like that in my first Forth program.  It
got tedious and I decided after a while that I was trying to force-fit
conventions from other languages onto Forth, and that this wasn't proper
Forth style.

[toc] | [prev] | [next] | [standalone]


#134674

Fromalbert@spenarnc.xs4all.nl
Date2026-03-15 11:42 +0100
Message-ID<nnd$1c631757$05855d8d@bef72ca663d8822c>
In reply to#134670
In article <877brednoq.fsf@nightsong.com>,
Paul Rubin  <no.email@nospam.invalid> wrote:
>albert@spenarnc.xs4all.nl writes:
>> I certainly do find DO unsatisfactory. I don't think it can be settled
>> unless we define the body as a lambda, an anonymous piece of code
>> that can be executed repeatedly.
>
>I now remember doing something like that in my first Forth program.  It
>got tedious and I decided after a while that I was trying to force-fit
>conventions from other languages onto Forth, and that this wasn't proper
>Forth style.

Did you use the proper starting point?
You must start with a denotation, valid in interpreter and compilation
mode that anonymously present an xt. (No environment imported, just
the behaviour)

I have no problem doing this. Suddenly UNLOOP makes more sense,
because in this context EXIT means "continue with the next
iteration".

Groetjes Albert
-- 
The Chinese government is satisfied with its military superiority over USA.
The next 5 year plan has as primary goal to advance life expectancy
over 80 years, like Western Europe.

[toc] | [prev] | [next] | [standalone]


#134689

FromPaul Rubin <no.email@nospam.invalid>
Date2026-03-15 13:27 -0700
Message-ID<87sea0dejp.fsf@nightsong.com>
In reply to#134674
albert@spenarnc.xs4all.nl writes:
> Did you use the proper starting point?
> You must start with a denotation, valid in interpreter and compilation
> mode that anonymously present an xt. (No environment imported, just
> the behaviour)

I think I used named functions, e.g.

  : FOO  .... whatever ... ;

  : BAR ['] FOO 5 TIMES ;

So TIMES took an xt and an execution count.  

[toc] | [prev] | [next] | [standalone]


#134677

FromKrishna Myneni <krishna.myneni@ccreweb.org>
Date2026-03-15 09:55 -0500
Message-ID<10p6h8l$163pl$1@dont-email.me>
In reply to#134664
On 3/14/26 09:13, albert@spenarnc.xs4all.nl wrote:
> In article <2026Mar14.115416@mips.complang.tuwien.ac.at>,

> The idea about +LOOP is also insane. If you have an increment, that must be
> defined once and for all.

Maybe I misunderstand what you are saying, but +LOOP does not use a 
fixed step. It uses whatever is on the stack, so the increment can vary 
from iteration to iteration.

--
Krishna

[toc] | [prev] | [next] | [standalone]


#134678

FromKrishna Myneni <krishna.myneni@ccreweb.org>
Date2026-03-15 10:01 -0500
Message-ID<10p6hl2$163pl$2@dont-email.me>
In reply to#134677
On 3/15/26 09:55, Krishna Myneni wrote:
> On 3/14/26 09:13, albert@spenarnc.xs4all.nl wrote:
>> In article <2026Mar14.115416@mips.complang.tuwien.ac.at>,
> 
>> The idea about +LOOP is also insane. If you have an increment, that 
>> must be
>> defined once and for all.
> 
> Maybe I misunderstand what you are saying, but +LOOP does not use a 
> fixed step. It uses whatever is on the stack, so the increment can vary 
> from iteration to iteration.
Example:

:noname 1000 0 do i . i 1+ +loop ; execute
0 1 3 7 15 31 63 127 255 511  ok

[toc] | [prev] | [next] | [standalone]


#134683

FromHans Bezemer <the.beez.speaks@gmail.com>
Date2026-03-15 19:11 +0100
Message-ID<nnd$0eba2e43$494d61ce@c5b3fa02bda6669c>
In reply to#134678
On 15-03-2026 16:01, Krishna Myneni wrote:
> On 3/15/26 09:55, Krishna Myneni wrote:
>> On 3/14/26 09:13, albert@spenarnc.xs4all.nl wrote:
>>> In article <2026Mar14.115416@mips.complang.tuwien.ac.at>,
>>
>>> The idea about +LOOP is also insane. If you have an increment, that 
>>> must be
>>> defined once and for all.
>>
>> Maybe I misunderstand what you are saying, but +LOOP does not use a 
>> fixed step. It uses whatever is on the stack, so the increment can 
>> vary from iteration to iteration.
> Example:
> 
> :noname 1000 0 do i . i 1+ +loop ; execute
> 0 1 3 7 15 31 63 127 255 511  ok
> 

No sweat!

: ex 0 999 for i . i 1+ step next ;  ok
ex 0 1 3 7 15 31 63 127 255 511  ok

Hans Bezemer

[toc] | [prev] | [next] | [standalone]


#134692

FromKrishna Myneni <krishna.myneni@ccreweb.org>
Date2026-03-15 19:36 -0500
Message-ID<10p7j9t$1if9d$1@dont-email.me>
In reply to#134683
On 3/15/26 13:11, Hans Bezemer wrote:
> On 15-03-2026 16:01, Krishna Myneni wrote:
>> On 3/15/26 09:55, Krishna Myneni wrote:
>>> On 3/14/26 09:13, albert@spenarnc.xs4all.nl wrote:
>>>> In article <2026Mar14.115416@mips.complang.tuwien.ac.at>,
>>>
>>>> The idea about +LOOP is also insane. If you have an increment, that 
>>>> must be
>>>> defined once and for all.
>>>
>>> Maybe I misunderstand what you are saying, but +LOOP does not use a 
>>> fixed step. It uses whatever is on the stack, so the increment can 
>>> vary from iteration to iteration.
>> Example:
>>
>> :noname 1000 0 do i . i 1+ +loop ; execute
>> 0 1 3 7 15 31 63 127 255 511  ok
>>
> 
> No sweat!
> 
> : ex 0 999 for i . i 1+ step next ;  ok
> ex 0 1 3 7 15 31 63 127 255 511  ok
> 

What does the following do when you substitute FOR ... STEP NEXT for DO 
... +LOOP ?

-1 1 rshift constant MAX-INT

MAX-INT DUP 2/ + CONSTANT LIM
MAX-INT 4 /      CONSTANT INCR

: ex LIM 0 DO I . CR INCR +LOOP ;

Per my understanding of the standard for +LOOP on 2's complement 64-bit 
systems, it should output the following.

0
2305843009213693951
4611686018427387902
6917529027641081853
9223372036854775804
-6917529027641081861
-4611686018427387910
  ok

--
Krishna

P.S. I had to fix the behavior of +LOOP in kForth-64 recently, to pass 
Gerry Jackson's coreplustest suite of tests for +LOOP.

[toc] | [prev] | [next] | [standalone]


#134698

FromHans Bezemer <the.beez.speaks@gmail.com>
Date2026-03-16 14:28 +0100
Message-ID<nnd$1dbe8cca$3ce0f993@cdc2010a93637f7c>
In reply to#134692
On 16-03-2026 01:36, Krishna Myneni wrote:
> On 3/15/26 13:11, Hans Bezemer wrote:
>> On 15-03-2026 16:01, Krishna Myneni wrote:
>>> On 3/15/26 09:55, Krishna Myneni wrote:
>>>> On 3/14/26 09:13, albert@spenarnc.xs4all.nl wrote:
>>>>> In article <2026Mar14.115416@mips.complang.tuwien.ac.at>,
>>>>
>>>>> The idea about +LOOP is also insane. If you have an increment, that 
>>>>> must be
>>>>> defined once and for all.
>>>>
>>>> Maybe I misunderstand what you are saying, but +LOOP does not use a 
>>>> fixed step. It uses whatever is on the stack, so the increment can 
>>>> vary from iteration to iteration.
>>> Example:
>>>
>>> :noname 1000 0 do i . i 1+ +loop ; execute
>>> 0 1 3 7 15 31 63 127 255 511  ok
>>>
>>
>> No sweat!
>>
>> : ex 0 999 for i . i 1+ step next ;  ok
>> ex 0 1 3 7 15 31 63 127 255 511  ok
>>
> 
> What does the following do when you substitute FOR ... STEP NEXT for DO 
> ... +LOOP ?
> 
> -1 1 rshift constant MAX-INT
> 
> MAX-INT DUP 2/ + CONSTANT LIM
> MAX-INT 4 /      CONSTANT INCR
> 
> : ex LIM 0 DO I . CR INCR +LOOP ;
> 
> Per my understanding of the standard for +LOOP on 2's complement 64-bit 
> systems, it should output the following.
> 
> 0
> 2305843009213693951
> 4611686018427387902
> 6917529027641081853
> 9223372036854775804
> -6917529027641081861
> -4611686018427387910
>   ok
> 
> -- 
> Krishna
> 
> P.S. I had to fix the behavior of +LOOP in kForth-64 recently, to pass 
> Gerry Jackson's coreplustest suite of tests for +LOOP.
> 
> 

  for compiling
   postpone 1+ postpone begin postpone over postpone over compiling
   postpone >r postpone >r postpone <  postpone while ; immediate
   ok
: -for compiling
   postpone 1- postpone begin postpone over postpone over compiling
   postpone >r postpone >r postpone >  postpone while ; immediate  ok
: step  postpone r> postpone + postpone r> postpone repeat ; immediate  ok
: next  postpone rdrop postpone rdrop ; immediate
   ok
-1 1 rshift constant MAX-INT  ok
   ok
MAX-INT DUP 2/ + CONSTANT LIM  ok
MAX-INT 4 /      CONSTANT INCR   ok
   ok
: ex 0 LIM 1- FOR I . CR INCR STEP NEXT ;  ok
ex  ok


It does what it is supposed to do: quit the loop, since 
-4611686018427387906 is smaller than 0. But what exactly do you want to 
prove here? That it does a signed compare? Doesn't that tell you exactly 
what one has to fix here - if you INSIST on having an unsigned 
comparison (which, IMHO was one of the worst decisions Forth-83 EVER 
made). I mean - how often have you used such a loop in general programming?

: for compiling
   postpone 1+ postpone begin postpone over postpone over compiling
   postpone >r postpone >r postpone <  postpone while ; immediate
     ok
: ufor compiling
   postpone 1+ postpone begin postpone over postpone over compiling
   postpone >r postpone >r postpone u<  postpone while ; immediate  ok
   ok
: -for compiling
   postpone 1- postpone begin postpone over postpone over compiling
   postpone >r postpone >r postpone >  postpone while ; immediate
   ok
: step  postpone r> postpone + postpone r> postpone repeat ; immediate
: next  postpone rdrop postpone rdrop ; immediate
   ok
   ok
-1 1 rshift constant MAX-INT
   ok
MAX-INT DUP 2/ + CONSTANT LIM
MAX-INT 4 /      CONSTANT INCR
   ok
: ex 0 LIM 1- UFOR I . CR INCR STEP NEXT ;
ok
ex 0
2305843009213693951
4611686018427387902
6917529027641081853
9223372036854775804
-6917529027641081861
-4611686018427387910
  ok


QED. If you can have a -FOR, why not a UFOR? Duh!

Hans Bezemer


[toc] | [prev] | [next] | [standalone]


#134703

FromKrishna Myneni <krishna.myneni@ccreweb.org>
Date2026-03-16 10:53 -0500
Message-ID<10p991u$23uka$1@dont-email.me>
In reply to#134698
On 3/16/26 08:28, Hans Bezemer wrote:
> On 16-03-2026 01:36, Krishna Myneni wrote:
>> On 3/15/26 13:11, Hans Bezemer wrote:
>>> On 15-03-2026 16:01, Krishna Myneni wrote:
>>>> On 3/15/26 09:55, Krishna Myneni wrote:
>>>>> On 3/14/26 09:13, albert@spenarnc.xs4all.nl wrote:
>>>>>> In article <2026Mar14.115416@mips.complang.tuwien.ac.at>,
>>>>>
>>>>>> The idea about +LOOP is also insane. If you have an increment, 
>>>>>> that must be
>>>>>> defined once and for all.
>>>>>
>>>>> Maybe I misunderstand what you are saying, but +LOOP does not use a 
>>>>> fixed step. It uses whatever is on the stack, so the increment can 
>>>>> vary from iteration to iteration.
>>>> Example:
>>>>
>>>> :noname 1000 0 do i . i 1+ +loop ; execute
>>>> 0 1 3 7 15 31 63 127 255 511  ok
>>>>
>>>
>>> No sweat!
>>>
>>> : ex 0 999 for i . i 1+ step next ;  ok
>>> ex 0 1 3 7 15 31 63 127 255 511  ok
>>>
>>
>> What does the following do when you substitute FOR ... STEP NEXT for 
>> DO ... +LOOP ?
>>
>> -1 1 rshift constant MAX-INT
>>
>> MAX-INT DUP 2/ + CONSTANT LIM
>> MAX-INT 4 /      CONSTANT INCR
>>
>> : ex LIM 0 DO I . CR INCR +LOOP ;
>>
>> Per my understanding of the standard for +LOOP on 2's complement 64- 
>> bit systems, it should output the following.
>>
>> 0
>> 2305843009213693951
>> 4611686018427387902
>> 6917529027641081853
>> 9223372036854775804
>> -6917529027641081861
>> -4611686018427387910
>>   ok
>>
>> -- 
>> Krishna
>>
>> P.S. I had to fix the behavior of +LOOP in kForth-64 recently, to pass 
>> Gerry Jackson's coreplustest suite of tests for +LOOP.
>>
>>
> 
>   for compiling
>    postpone 1+ postpone begin postpone over postpone over compiling
>    postpone >r postpone >r postpone <  postpone while ; immediate
>    ok
> : -for compiling
>    postpone 1- postpone begin postpone over postpone over compiling
>    postpone >r postpone >r postpone >  postpone while ; immediate  ok
> : step  postpone r> postpone + postpone r> postpone repeat ; immediate  ok
> : next  postpone rdrop postpone rdrop ; immediate
>    ok
> -1 1 rshift constant MAX-INT  ok
>    ok
> MAX-INT DUP 2/ + CONSTANT LIM  ok
> MAX-INT 4 /      CONSTANT INCR   ok
>    ok
> : ex 0 LIM 1- FOR I . CR INCR STEP NEXT ;  ok
> ex  ok
> 
> 
> It does what it is supposed to do: quit the loop, since 
> -4611686018427387906 is smaller than 0. But what exactly do you want to 
> prove here? That it does a signed compare? Doesn't that tell you exactly 
> what one has to fix here - if you INSIST on having an unsigned 
> comparison (which, IMHO was one of the worst decisions Forth-83 EVER 
> made). I mean - how often have you used such a loop in general programming?
> 
> : for compiling
>    postpone 1+ postpone begin postpone over postpone over compiling
>    postpone >r postpone >r postpone <  postpone while ; immediate
>      ok
> : ufor compiling
>    postpone 1+ postpone begin postpone over postpone over compiling
>    postpone >r postpone >r postpone u<  postpone while ; immediate  ok
>    ok
> : -for compiling
>    postpone 1- postpone begin postpone over postpone over compiling
>    postpone >r postpone >r postpone >  postpone while ; immediate
>    ok
> : step  postpone r> postpone + postpone r> postpone repeat ; immediate
> : next  postpone rdrop postpone rdrop ; immediate
>    ok
>    ok
> -1 1 rshift constant MAX-INT
>    ok
> MAX-INT DUP 2/ + CONSTANT LIM
> MAX-INT 4 /      CONSTANT INCR
>    ok
> : ex 0 LIM 1- UFOR I . CR INCR STEP NEXT ;
> ok
> ex 0
> 2305843009213693951
> 4611686018427387902
> 6917529027641081853
> 9223372036854775804
> -6917529027641081861
> -4611686018427387910
>   ok
> 
> 
> QED. If you can have a -FOR, why not a UFOR? Duh!
> 
>
I don't need six or seven variants of DO ... +LOOP. IMO, it's cleaner 
just to understand DO ... +LOOP and use it correctly.

--
KM

[toc] | [prev] | [next] | [standalone]


#134704

FromHans Bezemer <the.beez.speaks@gmail.com>
Date2026-03-16 19:25 +0100
Message-ID<nnd$7ebf6f1d$2d2acba2@4648ac821d92985a>
In reply to#134703
On 16-03-2026 16:53, Krishna Myneni wrote:
> On 3/16/26 08:28, Hans Bezemer wrote:
>> On 16-03-2026 01:36, Krishna Myneni wrote:
>>> On 3/15/26 13:11, Hans Bezemer wrote:
>>>> On 15-03-2026 16:01, Krishna Myneni wrote:
>>>>> On 3/15/26 09:55, Krishna Myneni wrote:
>>>>>> On 3/14/26 09:13, albert@spenarnc.xs4all.nl wrote:
>>>>>>> In article <2026Mar14.115416@mips.complang.tuwien.ac.at>,
>>>>>>
>>>>>>> The idea about +LOOP is also insane. If you have an increment, 
>>>>>>> that must be
>>>>>>> defined once and for all.
>>>>>>
>>>>>> Maybe I misunderstand what you are saying, but +LOOP does not use 
>>>>>> a fixed step. It uses whatever is on the stack, so the increment 
>>>>>> can vary from iteration to iteration.
>>>>> Example:
>>>>>
>>>>> :noname 1000 0 do i . i 1+ +loop ; execute
>>>>> 0 1 3 7 15 31 63 127 255 511  ok
>>>>>
>>>>
>>>> No sweat!
>>>>
>>>> : ex 0 999 for i . i 1+ step next ;  ok
>>>> ex 0 1 3 7 15 31 63 127 255 511  ok
>>>>
>>>
>>> What does the following do when you substitute FOR ... STEP NEXT for 
>>> DO ... +LOOP ?
>>>
>>> -1 1 rshift constant MAX-INT
>>>
>>> MAX-INT DUP 2/ + CONSTANT LIM
>>> MAX-INT 4 /      CONSTANT INCR
>>>
>>> : ex LIM 0 DO I . CR INCR +LOOP ;
>>>
>>> Per my understanding of the standard for +LOOP on 2's complement 64- 
>>> bit systems, it should output the following.
>>>
>>> 0
>>> 2305843009213693951
>>> 4611686018427387902
>>> 6917529027641081853
>>> 9223372036854775804
>>> -6917529027641081861
>>> -4611686018427387910
>>>   ok
>>>
>>> -- 
>>> Krishna
>>>
>>> P.S. I had to fix the behavior of +LOOP in kForth-64 recently, to 
>>> pass Gerry Jackson's coreplustest suite of tests for +LOOP.
>>>
>>>
>>
>>   for compiling
>>    postpone 1+ postpone begin postpone over postpone over compiling
>>    postpone >r postpone >r postpone <  postpone while ; immediate
>>    ok
>> : -for compiling
>>    postpone 1- postpone begin postpone over postpone over compiling
>>    postpone >r postpone >r postpone >  postpone while ; immediate  ok
>> : step  postpone r> postpone + postpone r> postpone repeat ; 
>> immediate  ok
>> : next  postpone rdrop postpone rdrop ; immediate
>>    ok
>> -1 1 rshift constant MAX-INT  ok
>>    ok
>> MAX-INT DUP 2/ + CONSTANT LIM  ok
>> MAX-INT 4 /      CONSTANT INCR   ok
>>    ok
>> : ex 0 LIM 1- FOR I . CR INCR STEP NEXT ;  ok
>> ex  ok
>>
>>
>> It does what it is supposed to do: quit the loop, since 
>> -4611686018427387906 is smaller than 0. But what exactly do you want 
>> to prove here? That it does a signed compare? Doesn't that tell you 
>> exactly what one has to fix here - if you INSIST on having an unsigned 
>> comparison (which, IMHO was one of the worst decisions Forth-83 EVER 
>> made). I mean - how often have you used such a loop in general 
>> programming?
>>
>> : for compiling
>>    postpone 1+ postpone begin postpone over postpone over compiling
>>    postpone >r postpone >r postpone <  postpone while ; immediate
>>      ok
>> : ufor compiling
>>    postpone 1+ postpone begin postpone over postpone over compiling
>>    postpone >r postpone >r postpone u<  postpone while ; immediate  ok
>>    ok
>> : -for compiling
>>    postpone 1- postpone begin postpone over postpone over compiling
>>    postpone >r postpone >r postpone >  postpone while ; immediate
>>    ok
>> : step  postpone r> postpone + postpone r> postpone repeat ; immediate
>> : next  postpone rdrop postpone rdrop ; immediate
>>    ok
>>    ok
>> -1 1 rshift constant MAX-INT
>>    ok
>> MAX-INT DUP 2/ + CONSTANT LIM
>> MAX-INT 4 /      CONSTANT INCR
>>    ok
>> : ex 0 LIM 1- UFOR I . CR INCR STEP NEXT ;
>> ok
>> ex 0
>> 2305843009213693951
>> 4611686018427387902
>> 6917529027641081853
>> 9223372036854775804
>> -6917529027641081861
>> -4611686018427387910
>>   ok
>>
>>
>> QED. If you can have a -FOR, why not a UFOR? Duh!
>>
>>
> I don't need six or seven variants of DO ... +LOOP. IMO, it's cleaner 
> just to understand DO ... +LOOP and use it correctly.
> 
> -- 
> KM
> 

Well, Anton seems to differ as well. He made lots of extra DO's to fix 
it. And FYI - you never use ?DO - IMHO it is the most useful one, since 
it's the only one that skips a LOOP when the loop parameters don't fit.

So - this proliferation of "DO's" has started already - and you embraced it.

Note that unlike your insistence to force an unsigned loop - which I 
doubt any Forther will ever encounter in the wild - "FOR" and "-FOR" 
would suffice.

Now - how are two variations of "DO" superior to two variations of 
"FOR"? Especially when you consider that the unsigned character of "DO" 
was in essence a misguided heritage of the 16-bit era?

I mean - how long have I programmed in Forth? And how often did I need 
an signed version of "DO"? Never.

First of all, I almost solely use counted loops when there is no "LEAVE" 
condition. Because it always becomes butt ugly - contrary to 
BEGIN..REPEAT loops (especially when REPEAT resolves ALL WHILE's ;-)

Second, the ranges stay well within the range of a signed integer - 
especially when you're doing 32- or 64-bit integers.

So - you don't need a whole slew of FOR variants. Two will do quite nicely.

Third, I like intentionality. "-FOR" means I intend to do a decrementing 
loop. "FOR" means I'm doing a vanilla incrementing loop. Just like (to 
me) "2DUP" means "I'm copying two related stack items" and "OVER OVER" 
means "I'm copying two non-related stack items". Like "C@+" means "I'm 
fetching a byte value - and increment the pointer" and "COUNT" means 
"I'm converting a counted string to an addr/count string".

I like to do my future me a service. And he thanks me.

Hans Bezemer

[toc] | [prev] | [next] | [standalone]


#134707

Fromalbert@spenarnc.xs4all.nl
Date2026-03-16 20:25 +0100
Message-ID<nnd$1658512b$2fd7e93a@2c9b6a7d53a2dd75>
In reply to#134703
In article <10p991u$23uka$1@dont-email.me>,
Krishna Myneni  <krishna.myneni@ccreweb.org> wrote:
<SNIP>
>I don't need six or seven variants of DO ... +LOOP. IMO, it's cleaner
>just to understand DO ... +LOOP and use it correctly.

You trade memory burden for insight. If you can do it, it
is advantageous. The formule for cos(a+b) is insane.
It you understand exp(i(a+b)) it falls in place.

I don't have a mensa level iq. If you want other people to
understand your programs, that is maybe not the right attitude.
Also if you are pushing eighty, (as I am), you risk that you no
longer understand your own programs.

>KM

Groetjes Albert
-- 
The Chinese government is satisfied with its military superiority over USA.
The next 5 year plan has as primary goal to advance life expectancy
over 80 years, like Western Europe.

[toc] | [prev] | [next] | [standalone]


#134708

FromKrishna Myneni <krishna.myneni@ccreweb.org>
Date2026-03-16 16:52 -0500
Message-ID<10p9u2i$2c680$1@dont-email.me>
In reply to#134707
On 3/16/26 2:25 PM, albert@spenarnc.xs4all.nl wrote:
> In article <10p991u$23uka$1@dont-email.me>,
> Krishna Myneni  <krishna.myneni@ccreweb.org> wrote:
> <SNIP>
>> I don't need six or seven variants of DO ... +LOOP. IMO, it's cleaner
>> just to understand DO ... +LOOP and use it correctly.
> 
> You trade memory burden for insight. If you can do it, it
> is advantageous. The formule for cos(a+b) is insane.
> It you understand exp(i(a+b)) it falls in place.
> 
> I don't have a mensa level iq. If you want other people to
> understand your programs, that is maybe not the right attitude.
> Also if you are pushing eighty, (as I am), you risk that you no
> longer understand your own programs.
> 

Admittedly it took me the better part of two days to figure out the 
logic to make +LOOP pass the coreplustest tests. However, most of the 
difficulty was getting the conceptual picture correct in my head for 
what it is intended to do. After that the coding wasn't that hard.

I don't have anything against someone coding a special variant or two of 
the stepped loops for signed integers, with different loop iteration 
behavior. But, one should be careful about the following

1) they are not replacements for DO ... +LOOP
2) they can also be misused
3) not to proliferate so many types of loops that it becomes a memory burden

--
KM

[toc] | [prev] | [next] | [standalone]


#134715

FromHans Bezemer <the.beez.speaks@gmail.com>
Date2026-03-17 14:24 +0100
Message-ID<nnd$0b222e3f$3a5c2078@767cb1b66c938993>
In reply to#134708
On 16-03-2026 22:52, Krishna Myneni wrote:
> On 3/16/26 2:25 PM, albert@spenarnc.xs4all.nl wrote:
>> In article <10p991u$23uka$1@dont-email.me>,
>> Krishna Myneni  <krishna.myneni@ccreweb.org> wrote:
>> <SNIP>
>>> I don't need six or seven variants of DO ... +LOOP. IMO, it's cleaner
>>> just to understand DO ... +LOOP and use it correctly.
>>
>> You trade memory burden for insight. If you can do it, it
>> is advantageous. The formule for cos(a+b) is insane.
>> It you understand exp(i(a+b)) it falls in place.
>>
>> I don't have a mensa level iq. If you want other people to
>> understand your programs, that is maybe not the right attitude.
>> Also if you are pushing eighty, (as I am), you risk that you no
>> longer understand your own programs.
>>
> 
> Admittedly it took me the better part of two days to figure out the 
> logic to make +LOOP pass the coreplustest tests. However, most of the 
> difficulty was getting the conceptual picture correct in my head for 
> what it is intended to do. After that the coding wasn't that hard.
> 
> I don't have anything against someone coding a special variant or two of 
> the stepped loops for signed integers, with different loop iteration 
> behavior. But, one should be careful about the following
> 
> 1) they are not replacements for DO ... +LOOP
> 2) they can also be misused
> 3) not to proliferate so many types of loops that it becomes a memory 
> burden
> 
> -- 
> KM
> 

Ad 1. Replacement in what sense? For legacy use - true, not a 
replacement. I never claimed it was;
Ad 2. Like COUNT (as C@+) or CMOVE (as a kind of fill replacement)? I'd 
say - join the club!
Ad 3. I'd have no problem coding this in Forth-79 on a Sinclair 
Spectrum. So I'm afraid you have to explain that one.

BTW, note that you can use a loop as an offset. Which means that if you 
need the higher areas, you can do an offset. Need the lower areas too? 
Use a second loop.

Or drop the whole idea and do all the 18446744073709551615 iterations 
with BEGIN..UNTIL and take a lunch break ;-)

Hans Bezemer

[toc] | [prev] | [next] | [standalone]


#134682

Fromalbert@spenarnc.xs4all.nl
Date2026-03-15 19:07 +0100
Message-ID<nnd$3634dbf7$66d80e8d@0a60c400ed02aaf9>
In reply to#134677
In article <10p6h8l$163pl$1@dont-email.me>,
Krishna Myneni  <krishna.myneni@ccreweb.org> wrote:
>On 3/14/26 09:13, albert@spenarnc.xs4all.nl wrote:
>> In article <2026Mar14.115416@mips.complang.tuwien.ac.at>,
>
>> The idea about +LOOP is also insane. If you have an increment, that must be
>> defined once and for all.
>
>Maybe I misunderstand what you are saying, but +LOOP does not use a
>fixed step. It uses whatever is on the stack, so the increment can vary
>from iteration to iteration.

Exactly. That is what wrong with it.
>
>--
>Krishna
>
-- 
The Chinese government is satisfied with its military superiority over USA.
The next 5 year plan has as primary goal to advance life expectancy
over 80 years, like Western Europe.

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.forth


csiph-web