| Store | Cart

Re: [TCLCORE] Question on coroutines

From: Neil Madden <Neil...@nottingham.ac.uk>
Tue, 8 Dec 2009 13:10:36 +0000
On 7 Dec 2009, at 14:44, Kevin Kenny wrote:
> Neil Madden wrote:>> Or perhaps "yield [list foo bar]" and have the caller do "eval [$coro]"? Isn't that exactly what yieldTo does, but hiding the [eval], or am I still missing something?> > You're not missing much. It's a minor simplification; if the coro were> always invoked with [eval [$coro]], then [yield] would behave the same> as [yieldto] without it.  In that case, though, if the coro is actually> ready to return a value, it would have to execute something like> [yield [list return -level 0 $value]].  And the tangle gets more> complicated, because the dispatcher isn't a simple [eval [$coro]];> it has to continue evaluating a whole chain of control transfers> (and still be able to escape with [return -level 0] or whatever at> the end).> > Equivalent power, different notation.

OK, I sort-of see now. Wrapping all the coroutine yields in an [eval] is easily accomplished:

 proc coro {name args} {
    coroutine $name.coro {*}$args
    interp alias {} $name {} dispatch $name.coro
 }
 proc dispatch {coro arg} { eval [$coro $arg] }

To yield a value, you can just do (as you say):

 proc value val { list return -level 0 $val }
 yield [value $foo]

I'm not sure I see in what case the dispatcher needs to do more than a simple [eval], though. In what situation do you get a chain of control transfers with yieldTo? (My understanding is that this behaves like [tailcall], so there should be no chains).

Not that I am antagonistic to the proposal, I'm just trying to determine if it is a lack of expressive power in the original coroutine specification, or a syntactic nicety.

NeilThis message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Tcl-Core mailing list
Tcl-...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-core

Recent Messages in this Thread
miguel sofer Dec 05, 2009 10:25 pm
Donal K. Fellows Dec 07, 2009 01:04 am
Kevin Kenny Dec 07, 2009 02:47 am
Larry McVoy Dec 07, 2009 02:56 am
Kevin Kenny Dec 07, 2009 04:41 am
Neil Madden Dec 07, 2009 09:35 am
miguel sofer Dec 07, 2009 01:41 pm
Kevin Kenny Dec 07, 2009 02:24 pm
Donal K. Fellows Dec 07, 2009 01:08 pm
miguel sofer Dec 07, 2009 01:20 pm
Donal K. Fellows Dec 07, 2009 02:09 pm
miguel sofer Dec 07, 2009 02:24 pm
miguel sofer Dec 07, 2009 04:44 pm
Neil Madden Dec 07, 2009 02:31 pm
Kevin Kenny Dec 07, 2009 02:44 pm
Neil Madden Dec 08, 2009 01:10 pm
Donald G Porter Dec 08, 2009 02:15 pm
miguel sofer Dec 08, 2009 02:22 pm
Kevin Kenny Dec 07, 2009 02:33 pm
Joe English Dec 08, 2009 06:08 pm
miguel sofer Dec 08, 2009 06:15 pm
Messages in this thread