Liste des Groupes | Revenir à cl forth |
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:FWIW a single quotation-based counter in another Forth:The :}D means that the closure data is stored in the dictionary; there>
is also :}L (for locals, deallocated when the surrounding definition
is exited), :}H (heap, deallocated with FREE-CLOSURE), and :}H1 (heap,
deallocated right after the first (and only) execution).
This is pretty cool, but it looks like quotations within the closure
aren't allowed to access the closure's locals, using them as OOP-like
state. In the current Gforth git snapshot:
>
: x [{: n :}d [: n 1+ dup to n ;] ;]h 0 execute ;
>
gives:
>
*the terminal*:26:30: error: Unsupported operation
: x [{: n :}d [: n 1+ dup to >>>n<<< ;] ;]h 0 execute ;
>
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.
Les messages affichés proviennent d'usenet.