lua-users home
lua-l archive

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


David Kastrup wrote:
[...]
> It would be nice if labels were callable in a
> similar way.

Algol-68 does this; a label can be cast to a parameterless function
pointer, Calling the function does a longjmp to the label, thus allowing
this sort of thing:

  proc openfile = (ref string filename, proc void onerror) int:
  (
    int fd = open(filename, "r");
    if (fd = -1) then
      onerror
    fi;
    fd
  );

  openfile("missing", abort);
  ...
  abort:
  print("Error!")

This provides a nice middle ground between simple labels and full-on
continuations --- but, of course, it's mostly useful for error recovery
as in the above example, and Lua's exceptions form a better way of
handling this.

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "I have always wished for my computer to be as easy to use as my
│ telephone; my wish has come true because I can no longer figure out
│ how to use my telephone." --- Bjarne Stroustrup

Attachment: signature.asc
Description: OpenPGP digital signature