lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




2011/6/15 David Kastrup <dak@gnu.org>
"Joseph Manning" <manning@cs.ucc.ie> writes:

> On 2011-Jun-15 (Wed) at 00:59 (-0400), phlnc8 wrote:
>
>>> On Mon, Jun 13, 2011 at 4:27 PM, Alexandre Erwin Ittner
>>> <alexandre@ittner.com.br> wrote:
>>> ...
>>> > A "label" keyword would be great too
>>>
>>>  I like this idea of a "label" reserved word.
>
> +1

There has been some notion of making coroutines callable like
subroutines, more or less making coroutine.wrap a one-shot operation for
setting up a coroutine.  It would be nice if labels were callable in a
similar way.  However, a function or coroutine can be put into a
variable, calling the variable later, and that does not appear to work
reasonably well for forward jumps.  One could possibly work with forward
declarations:

xxx = label zzz
[...]
xxx() -- jumps forward
[...]
(label zzz)() -- jumps forward
[...]
label zzz
[...]
zzz() -- jumps backwards

The next obvious extension is arguments.  Soon we are at Scheme's named
let and then at continuations.

Of course, one should try figuring out where to draw a sensible line
that does not sacrifice comprehensibility for elegance.  But I think it
reasonable to try finding a way where the flow control transfers of
resuming a thread, calling a function, and jumping to a label are all
wrapped into a suitably uniform syntax.

--
David Kastrup



Is this OK? makes goto and label functions:

goto "here"
print "never reach here"
label "here"
print "reach here"

or, makes label a object:
local here = local()
here:goto()
print"never reach here"
here:archor()
print "reach here"