[LEPL] trampolining and continuation passing style

14 views
Skip to first unread message

shaunc

unread,
Apr 17, 2010, 4:07:05 PM4/17/10
to lepl
Andrew,

I have been using continuation-passing style for some tasks (which I'm
familiar with from a rudimentary facility in haskell). I'm intrigued
by your use of python trampolining in lepl. Is lepl a good place to
study how this is done? Did you have other sources or articles that
were helpful to you when you designed lepl that you can recommend?

Thanks,

-- Shaun Cutts

--
You received this message because you are subscribed to the Google Groups "lepl" group.
To post to this group, send email to le...@googlegroups.com.
To unsubscribe from this group, send email to lepl+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/lepl?hl=en.

andrew cooke

unread,
Apr 17, 2010, 7:38:46 PM4/17/10
to le...@googlegroups.com

Trampolining in Python is actually quite tricky to do correctly (including
exception handling). At least, I have found it so.

I started with the Python library test code, written by Tim Peters, and linked
in the Lepl credits. I'd suggest reading and understanding that before
looking at Lepl:
http://www.koders.com/python/fid9B99238B5452E1EDA851459C2F4B5FD19ECBAD17.aspx?s=mdef%3Amd5

Here are my initial notes on that: http://www.acooke.org/cute/RecursiveG0.html

There are more notes here, but they're rather cryptic and include wrong turns:
http://www.acooke.org/cute/Avoidingth0.html


Looking at the notes I made over the years, I found this blog post, which was
quite popular, and which introduces the basic concepts, but it doesn't really
get to full co-routines:
http://eli.thegreenplace.net/2009/08/29/co-routines-as-an-alternative-to-state-machines/

That blog post references http://www.dabeaz.com/coroutines/index.html which
also avoids the hardest parts (if I remember correctly), but which is also a
good place to start.


The above is a bit chaotic, so to summarise, I'd suggest reading the following
in the order given:
http://eli.thegreenplace.net/2009/08/29/co-routines-as-an-alternative-to-state-machines/
http://www.dabeaz.com/coroutines/index.html
http://www.koders.com/python/fid9B99238B5452E1EDA851459C2F4B5FD19ECBAD17.aspx?s=mdef%3Amd5


If you want to look at the Lepl code too, the trampoline itself is here -
http://www.acooke.org/lepl/api/lepl.core.parser-pysrc.html#trampoline - but
the coroutines are generated using decorators which makes them much less
readable - http://www.acooke.org/lepl/api/lepl.matchers.support-pysrc.html -
so I doubt it's going to be very helpful.

Good luck - I'm happy to answer more questions either here or via direct email
if you want, but I am not very good at explaining things - I am a self taught
programmer and rely too much on intuition...

Andrew
Reply all
Reply to author
Forward
0 new messages