lua-users home
lua-l archive

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

Hi Rici,

Don't you think it can get quite complicated to trace where these blocks reside once you start passing them around?

No, I don't.

I didn't mean it would be hard to implement. I meant it might make the
Lua code that uses this functionality very hard to understand. This
could be a limitation of my not being used to non-local returns.  I
remember once not liking coroutines. :)

But I do think we have found a valid use for this non-local return:
error checking.

Wouldn't a simplistic solution be enough, though? How about a construct
that behaves exactly like return, but that forces return of more than
one level? I have no idea of what would be an elegant syntax for that,
so I will go with a function call.

    function roe(v, ...)
       if v then return v, ...
       else nlr(2, v, ...) end

    function foo()
        local c = roe(socket.connect("localhost", 80))
        roe(socket.send("GET / HTTP/1.0\r\n\r\n"))
        local l = roe(socket.receive())
        return 1

Naturally, by orthogonality one would expect to have functionality to
break across more than one iteration block...  I didn't want to go there
because this has already been discussed in the list (long time ago,
labeled breaks, right?). The conclusion was that it wasn't used often
enough to be included in the language.

Non-local returns *would* be used often...