[e-lang] Q: asynchronous tail recursion?
Kevin Reid
kpreid at mac.com
Wed Dec 27 22:35:49 CST 2006
On Dec 27, 2006, at 9:21, Kevin Reid wrote:
> On Dec 27, 2006, at 5:22, Constantine Plotnikov wrote:
>
>> Is tail recursion supported for asynchronous loops in E? My current
>> guess (based on E.send*() API) that tail recursion for asynchronous
>> processes is not supported for loops that return a value and it
>> cannot
>> be supported unless changes to API and to kernel E expansions are
>> made.
>
> *If* this is in fact a problem, which I'm not sure about, then I
> think it can be fixed as part of the implementation: any time a
> promise is resolved to another promise, the resolved-ref should do a
> whenMoreResolved on its target, changing its target whenever it gets
> a response. This would ensure that there is at most one layer of
> resolved promise in any such resolution chain.
MarkM pointed out that this puts the leakage elsewhere: the most
recent promise in the chain will accumulate queued __whenMoreResolved
messages until the final resolution.
We have discussed an implementation technique that we think will work:
As above, except that instead of using __whenMoreResolved, promises
have a weak set or weak-keyed map containing all forwarding
references (former promises, what I called resolved-ref above) which
refer to that promise.
When a promise is resolved, it updates (shortens) every forwarding-
ref to point to its resolution (and discards the set).
This is equivalent to the previous mechanism except that the
intermediate promises and their requests for shortening are not
retained by anything, and so can be discarded.
--
Kevin Reid <http://homepage.mac.com/kpreid/>
More information about the e-lang
mailing list