[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: continuations (was Re: error() or nil, 'error msg')
- From: William Ahern <william@...>
- Date: Wed, 24 Sep 2014 14:07:16 -0700
On Wed, Sep 24, 2014 at 03:54:37PM -0400, Tom N Harris wrote:
> On Wednesday, September 24, 2014 12:55:15 PM Sean Conner wrote:
> > How is that any different from BASIC's "on error goto ... " statement?
> >
> > Also, you have the ability to jump to labels in an outer function, but it
> > involves pcall()/error() ...
<snip>
> As Roberto says, a broader goto would be a form of continuation. On the
> other hand, aren't most use cases for continuations also handled by
> coroutines? The one that comes to my mind is futures. In fact, right now
> the way I see this being implemented is by hoisting the function into an
> implicit coroutine. Then what happens if it's part of an explicit
> coroutine?
You could monkey patch coroutine.resume so that it detects a unique return
variable used by the function (in my case, cqueues.poll) that is trying to
yield to a special caller. I sometimes use this technique with my event
library to forward yields until reaching an event scheduler. That way
application code can use coroutine.wrap to create iterators without worrying
about interfering with the non-blocking I/O yield/resume protocol.