home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.forth      Forth programmers eat a lot of Bratwurst      117,927 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 117,064 of 117,927   
   Paul Rubin to Anton Ertl   
   Re: Back & Forth - Co-routines   
   09 Feb 25 09:55:29   
   
   From: no.email@nospam.invalid   
      
   anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:   
   > 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.   
      
   It would be interesting if your conservative gc could be made reliable   
   and included with gforth, and then another suffix could be added to put   
   closure locals in the gc'd heap.  "Reliable" = scan the return and   
   locals stacks, via suitable extensions added to GC.  Also in a threaded   
   program I guess it would have to stop any threads that shared a GC'd   
   heap during collection of that heap.   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca