: iterator: ( "name" -- xt ) \ xt of quotation
: ]] true begin [: [[
save-input ]] scan-words [[ restore-input
abort" Error: RESTORE-INPUT failed"
;
HunptyDumpty introduced his Y Combinator in this post: >https://groups.google.com/g/comp.lang.forth/c/ea59-OtiLvE/m/TH_8t9c7BgAJ
with the definition
: yc ( .. xt xt |0 -- .. ) begin while execute repeat ;
An example from HD's post:
: downcount dup . 1- dup 0 >= IF xt dup ELSE 0 THEN ;
where xt is the execution token of downcount.
Having experimented with iterators to avoid having to get the xt of a
word I tried using a quotation:
: foo [: <body of downcount> ;] yc ;
--
Gerry
In article <10edrl7$3v2bf$[email protected]>,
Gerry Jackson <[email protected]> wrote:
HunptyDumpty introduced his Y Combinator in this post: >>https://groups.google.com/g/comp.lang.forth/c/ea59-OtiLvE/m/TH_8t9c7BgAJ >>with the definition
: yc ( .. xt xt |0 -- .. ) begin while execute repeat ;
An example from HD's post:
: downcount dup . 1- dup 0 >= IF xt dup ELSE 0 THEN ;
where xt is the execution token of downcount.
Having experimented with iterators to avoid having to get the xt of a
word I tried using a quotation:
: foo [: <body of downcount> ;] yc ;
I favour the { .. } notation that also replaces :NONAME .. ;
an index is indispensable in DO , otherwise you have a
BEGIN .. WHILE .. REPEAT so no flags.
While we are at it:
- limits in ascending order
- inclusive limits
- no unsigned bullshit
and a DO defined like:
lowbound upbound(inclusive) xt DO
in the body of xt IX is the loop variable.
LEAVE works as before.
Experiments shows that this works in interpretation mode, thanks to
{ }
: foo 1 10 { "we gaan naar Rome" TYPE CR } DO ;
1 10 { "we gaan naar Rome" TYPE CR } DO
And you can do things like
: foo 1 10 { "we gaan naar Rome" TYPE CR } DO ;
: DO) >R >R 0 R> 1- R> ; ( n , range [0,n) ) 1]
: DO] >R >R 1 R> R> ; ( n , range (0,n] ) 1]
And no unsigned indices
FFFF,FFFF,FFFF,0000 7000,0000,000F,FFFF (empty range nothing happens)
and no quasi infinite loops like--
0 0 DO once for index 0.
(This I have implemented in the experimental language lucky7).
1] mathematical notation, the upper lower limit is in the set.
----
Gerry
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.
On 04/11/2025 21:36, Gerry Jackson wrote:
: iterator: ( "name" -- xt ) \ xt of quotation
: ]] true begin [: [[
save-input ]] scan-words [[ restore-input
abort" Error: RESTORE-INPUT failed"
;
I just realised to my embarassment that this is unduly complicated. Of course the scanning is not required. All that is needed for iterator: is simply:
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,076 |
| Nodes: | 10 (1 / 9) |
| Uptime: | 78:38:35 |
| Calls: | 13,805 |
| Files: | 186,990 |
| D/L today: |
5,986 files (1,957M bytes) |
| Messages: | 2,443,207 |