Re: NRE committed: PLEASE TEST
- From: Neil Madden <nem@xxxxxxxxxxxxx>
- Date: Wed, 03 Sep 2008 20:19:33 +0100
Fredderic wrote:
miguel <msofer@xxxxxxxxxxxx> wrote:
Fredderic wrote:[yield] would be a handy way to allow a [proc] to do someOh - now I understood what you mean. This would make procs a bit
initialisation on first run.
heavier than coroutines (see below).
I kind of figured that, and pretty much wiped that idea myself.
My wish here would be served by the [coroutine] command being able to
displace an existing proc or command until it completes. Having
[coroutine] displace the current proc with an inline [apply] invocation
(as DKF mentioned is possible), would allow exactly the semantics I was
rather hoping would be possible. A proc could then trivially be built
that can [yield] without having to be explicitly invoked through
[coroutine].
A limitation of this approach is that you couldn't have 2 or more simultaneous coroutine instances based on the same command. Another difficulty is that the original proc may take different arguments than the resume command. You should be able to write something like this if you want, though:
proc coproc {name params body} {
set f [list $params $body]
interp alias {} $name {} coproc:spawn $name $f
}
proc coproc:spawn {name f args} {
coroutine $name ::apply $f {*}$args
}
(restoring the original proc left as an exercise).
As currently implemented, it would also prevent the second and later
calls to take more than one argument.
Dare I ask, why? ;)
If you think about how the mechanism works, a coroutine suspends from a yield, and is later resumed from that place. Any arguments to the resume become the result of the yield as far as the coroutine is concerned:
set next [yield $val]
Therefore, if the resume command could take multiple arguments then it would be impossible to distinguish between multiple separate arguments and a list. You could maybe extend yield, something like:
yield $val here are the resume args
but I think the original is sufficient.
[...]
My focus on this issue, btw, is mostly in the interest of allowing
coroutines to be used as an implementation detail in the construction
of a proc, rather than a project-wide design decision from the outset.
I think _if_ it can be done without too much effort, it would be a
fantastically handy way to do the first-run initialisation thing.
Coroutines should be possible to use as an implementation detail, as in my worked example converting a simple synchronous program to use the event loop: http://wiki.tcl.tk/21532
-- Neil
.
- Follow-Ups:
- Re: NRE committed: PLEASE TEST
- From: Fredderic
- Re: NRE committed: PLEASE TEST
- Prev by Date: Re: Converting a (big) canvas to an image
- Next by Date: WshShell??
- Previous by thread: Re: NRE committed: PLEASE TEST
- Next by thread: Re: NRE committed: PLEASE TEST
- Index(es):
Relevant Pages
|