Info on continuations?

V

vasudevram

Hi,

I am Googling and will do more, found some stuff, but interested to get
viewpoints of list members on:

Continuations in Python.

Saw a few URLs which had some info, some of which I understood. But
like I said, personal viewpoints are good to have.

Thanks
Vasudev
-------------------------------------------------------------------------------------------------------------------------
Software consulting and training
http://www.dancingbison.com
PDF conversion toolkit: http://sourceforge.net/projects/xtopdf (stable
version 1.0, supports
plain text and DBF conversions to PDF)
-------------------------------------------------------------------------------------------------------------------------
 
O

olsongt

vasudevram said:
Hi,

I am Googling and will do more, found some stuff, but interested to get
viewpoints of list members on:

Continuations in Python.

Saw a few URLs which had some info, some of which I understood. But
like I said, personal viewpoints are good to have.

Thanks
Vasudev

Could you be a little more specific on what you're looking for?
Continuations are a big can of worms.

In general, some of the historical uses of continuations are better
represented as classes in python. Generators provide some limited
functionality as well, and will be able to send info both ways in
python 2.5 to enable limited co-routines. Stackless python allows you
to *really* suspend the stack at a given time and do a bunch of crazy
stuff, but doesn't currently support 'full continuations'.
 
V

vasudevram

Could you be a little more specific on what you're looking for?
Continuations are a big can of worms.

Thanks for the reply. Can't really be more specific, since I don't know
enough. The question and the interest was exploratory in nature - as
part of wanting to learn more about some dynamic / advanced features of
Python. Will Google more and read the docs ...

Vasudev
 
M

Michele Simionato

vasudevram said:
Hi,

I am Googling and will do more, found some stuff, but interested to get
viewpoints of list members on:

Continuations in Python.

Python does not have (full) continuations. If you want to understand
continuations,
you need a language that supports them. For instance this is a recent
reference for continuations in Scheme:
http://www-128.ibm.com/developerworks/linux/library/l-advflow.html?ca=dgr-lnxw02FlowControl

Ruby should have support for continuations too, but I am quite ignorant
about the Ruby literature.

Michele Simionato
 
M

Michael

vasudevram said:
Hi,

I am Googling and will do more, found some stuff, but interested to get
viewpoints of list members on:

Continuations in Python.

Saw a few URLs which had some info, some of which I understood. But
like I said, personal viewpoints are good to have.

Python doesn't really support continuations. Generators (and co-routines in
general) have similar properties to continuations, however they're not
continuations. Closures are also sometimes considered cousins to
continuations, and python's support for those is pretty good IMO. (again
however, closures are not continuations).

Since it looks like you're also looking for what continuations are, I think
the following is the simplest way of explaining them. If you've ever
programmed in BASIC, *in a way* if you think of methods/functions as a
named GOSUB, then continuation (in a way) are a way of giving a name to a
goto (it's more subtle than that though since a continuation os often
defined to "remember" state in a similar way to a closure). Like a function
you can pass them round as objects. Like a generator/closure they remember
the state they were in.

*Personally* , I think python NOT supporting full continuations is a GOOD
thing, since full continuations, whilst powerful, are also a great source
of confusion for people. (That said, I have a usecase I'd find them useful
for - I think they'd be useful for plugin architectures - but IMO that
doesn't outweigh the risk of code obfuscation :)

One particular usecase that people seem to like continuations for,
specifically how they're used in seaside, is actually a subset of
functionality that python *can* support (to a large extent).

Essentially the idea is to be able to take a web application and make it
look linear. CherryFlow allows you for example to write this:

@expose
@flow
def example_flow():
yield view.first_page()
if request.args["choice"] == "a":
yield view.choice_a_page()
else:
yield view.choice_b_page()
yield view.last_page()

(example from: http://tinyurl.com/qzpqu )

This causes the user's browser to show a page where they have a choice of
"a" or "b". Depending on what they choose, they then either are presented
with choice_a_page or choice_b_page. Finally, no matter which option they
chose, you are presented with the last page.

Something similar can be done using Kamaelia, though at present only the
mechanism exists there, without any sugar (http://tinyurl.com/n3bh7 -
specifically websiteSessionExampleComponent). The reason I mention it is to
say that it's relatively simple to do using python :)

I have to stress though, this usage of continuations in Seaside, as
emulate-able in python is a subset of the full power of continuations,
which isn't available in python at present. (Though it's possible hacking
greenlets could result in something). (In fact the way seaside uses them as
far as I can tell is more to implement co-routine like behaviour than
anything else (!))

Anyway, hope that's interesting/useful - looking at your other comments,
you're just looking for information and usecases at the moment :)

Regards,


Michael.
 
V

vasudevram

Michael said:
vasudevram said:
Hi,

I am Googling and will do more, found some stuff, but interested to get
viewpoints of list members on:

Continuations in Python.

Saw a few URLs which had some info, some of which I understood. But
like I said, personal viewpoints are good to have.

Python doesn't really support continuations. Generators (and co-routines in
general) have similar properties to continuations, however they're not
continuations. Closures are also sometimes considered cousins to
continuations, and python's support for those is pretty good IMO. (again
however, closures are not continuations).

Since it looks like you're also looking for what continuations are, I think
the following is the simplest way of explaining them. If you've ever
programmed in BASIC, *in a way* if you think of methods/functions as a
named GOSUB, then continuation (in a way) are a way of giving a name to a
goto (it's more subtle than that though since a continuation os often
defined to "remember" state in a similar way to a closure). Like a function
you can pass them round as objects. Like a generator/closure they remember
the state they were in.

*Personally* , I think python NOT supporting full continuations is a GOOD
thing, since full continuations, whilst powerful, are also a great source
of confusion for people. (That said, I have a usecase I'd find them useful
for - I think they'd be useful for plugin architectures - but IMO that
doesn't outweigh the risk of code obfuscation :)

One particular usecase that people seem to like continuations for,
specifically how they're used in seaside, is actually a subset of
functionality that python *can* support (to a large extent).

Essentially the idea is to be able to take a web application and make it
look linear. CherryFlow allows you for example to write this:

@expose
@flow
def example_flow():
yield view.first_page()
if request.args["choice"] == "a":
yield view.choice_a_page()
else:
yield view.choice_b_page()
yield view.last_page()

(example from: http://tinyurl.com/qzpqu )

This causes the user's browser to show a page where they have a choice of
"a" or "b". Depending on what they choose, they then either are presented
with choice_a_page or choice_b_page. Finally, no matter which option they
chose, you are presented with the last page.

Something similar can be done using Kamaelia, though at present only the
mechanism exists there, without any sugar (http://tinyurl.com/n3bh7 -
specifically websiteSessionExampleComponent). The reason I mention it is to
say that it's relatively simple to do using python :)

I have to stress though, this usage of continuations in Seaside, as
emulate-able in python is a subset of the full power of continuations,
which isn't available in python at present. (Though it's possible hacking
greenlets could result in something). (In fact the way seaside uses them as
far as I can tell is more to implement co-routine like behaviour than
anything else (!))

Anyway, hope that's interesting/useful - looking at your other comments,
you're just looking for information and usecases at the moment :)

Regards,


Michael.

Yes, that's quite right - only looking for info and use cases at
present - and thanks for the info, it was interesting and useful :)
Need to check all the inputs out ...

Vasudev
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top