[plt-scheme] Fun with Unicode and delimited continuations
On Jun 3, Matthias Felleisen wrote:
> On Jun 3, 2010, at 12:31 PM, John Clements wrote:
>
> >> Sorry, maybe this wasn't clear: I mean e.g. the python 'yield',
> >> which allows a function to return multiple values in a serialized
> >> form.
>
> If you can write a yield + create a two-element structure in Python
> that way, you can mimic delimited continuations.
>
>
> > The only problem with this mechanism is that the yield boundary is
> > fixed on entry to the function call.
>
> That's minor. Reset is next to the function entry point too.
>
> Go for it. Show us that Python has delimited continuations.
Here's some quick code:
#lang scheme
(require scheme/generator)
(define (foo x y) (yield x) (yield (+ x y)))
(define (bar a b c)
(generator ; v5 will require () after `generator'
(for* ([x (in-generator (foo a b))]
[y (in-generator (foo x c))])
(yield y))))
(define g (bar 100 10 1))
(g) (g) (g) (g)
where `foo' is the moral equivalent of plus/minus. Given that this
uses exactly the feature that scheme/generator has that python doesn't
(it uses a dynamic `yield' so it can be used in "helper" functions),
it would be interesting to see if there's a way to do that in python.
(I think that Jon looked for an example that shows the difference.)
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!