Sujet : Re: Back & Forth - Co-routines
De : melahi_ahmed (at) *nospam* yahoo.fr (ahmed)
Groupes : comp.lang.forthDate : 10. Feb 2025, 07:14:52
Autres entêtes
Organisation : novaBBS
Message-ID : <b61181aa898f82d521f9fd38d4fa8409@www.novabbs.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12
User-Agent : Rocksolid Light
On Sun, 9 Feb 2025 23:08:22 +0000, Anton Ertl wrote:
Paul Rubin <no.email@nospam.invalid> writes:
..
This is an attempt to make a counting function, like in Scheme:
>
(define (x)
((lambda (n)
(lambda ()
(set! n (+ 1 n))
n)) 0))
>
(define a (x))
>
(a) ; 1
(a) ; 2, etc.
>
: x ( -- xt )
here 0 , [{: addr :}d addr @ 1+ dup addr ! ;] ;
>
x alias a
x alias b
a . \ 1
a . \ 2
b . \ 1
a . \ 3
>
Hi,
But I can do it like this:
: ctr: create 0 , does> dup @ 1+ dup rot ! ; ok
ctr: a
ctr: b
a . 1 ok
b . 1 ok
a . 2 ok
b . 2 ok
b . 3 ok
So, what is the difference between the two definitions?
- anton
Ahmed
--