[plt-scheme] tree->generator from t-y-scheme question
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> Folks,
>
> I'm looking at the tree traversal with continuations example in Teach
> Yourself Scheme in Fixnum Days. I think I have an almost complete grasp
> on it but I'm missing one bit of info.
>
> In generate-leaves:
>
> ...
> (else
> (call/cc
> (lambda (rest-of-tree)
> (set! generate-leaves
> (lambda ()
> (rest-of-tree 'resume)))
> (caller tree))))))
>
> Is it correct to say that rest-of-tree is passed 'resume because
> generate-leaves takes no parameters?
Yes, 'resume is just a dummy value, because a continuation always takes one
argument, but it is not needed here.
>
> What is the rest-of-tree continuation in this scenario, i.e. where's the
> "hole"?
The call/cc expression itself is the "hole". When the
rest-of-tree-continuation is called, this "hole" is filled with value
it takes. Nothing is done with the value of the call/cc statement,
therefor the dummy-value.
>
> ...
> ((generate-leaves
> (lambda ()
> (let loop ((tree tree))
> ...
>
> Are we starting at the "let" here and assigning the remainder of the tree
> to tree?
Yes, that is correct.
The first time the generator is called, generate-leaves is a normal
function, which uses the caller to jump out of its loop and return a
leaf. But after this generate-leaves is now a continuation that
"continues" the traversal.
So in short: with caller you jump out of the loop, and with
generate-leave you jump back in to the loop.
I hope this makes sense :)
I think the example would be more clear if the 2 continuations where
called: return and continue.
>
> Thanks, Joel
>
> --
> OpenPoker: The Linux of poker software
> http://wagerlabs.com/forums
>
>
>