[plt-scheme] Another continuation question
On Sat, Jul 19, 2008 at 4:03 PM, Grant Rettke <grettke at acm.org> wrote:
> In a thread that I can't find,
Check out blog.plt-scheme.org last July and August, and of course this list
at the same time.
> I'm pretty sure that Matthias posted
> some interesting "self modifying code" that looked like this, which I
> found on:
>
> http://en.wikipedia.org/wiki/Call-with-current-continuation
>
> ;; [LISTOF X] -> ( -> X u 'you-fell-off-the-end-off-the-list)
> (define (generate-one-element-at-a-time a-list)
> ;; (-> X u 'you-fell-off-the-end-off-the-list)
> ;; this is the actual generator, producing one item from a-list at a time
> (define (generator)
> (call/cc control-state))
> ;; [CONTINUATION X] -> EMPTY
> ;; hand the next item from a-list to "return" (or an end-of-list marker)'
> (define (control-state return)
> (for-each
> (lambda (an-element-from-a-list)
> (call/cc
> (lambda (resume-here)
> (set! control-state resume-here)
> (return an-element-from-a-list))))
> a-list)
> (return 'you-fell-off-the-end-off-the-list))
> ;; time to return the generator
> generator)
>
> (define gen (generate-one-element-at-a-time '(a b c)))
> (gen)
> (gen)
> (gen)
> (gen)
>
> This is another chunk of code that worked fine in v372, and per the
> thread [Confusing continuation behavior (a question about)], I suspect
> that the code shouldn't have worked, because now it goes into an
> endless loop?
I suspect that what changed is that for each is now looking up
'control-state
only once, so changing it with set! does nothing. That said, I know almost
nothing about
what I am talking about here.
>
>
> I'm migrating all of my collected code snips from 3 to 4, perhaps the
> solution is the same as the other thread, but I haven't figured that
> one out yet ;).
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080719/13552ab6/attachment.html>