lua-users home
lua-l archive

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


I am afraid that this post may sound a bit rude - so apologies in
advance...

The semantics of "a:b(c)" is already defined, and in a way that is not
going to change; and at present an "a:b" without the "(...)"
afterwards just raises a syntax error.

People are now discussing, for the n-th time, a FIXED semantics for
"a:b" without the "(...)" - as if there could be an agreement!...

Wouldn't it be much more Lua-ish to just create a new metamethod for
that? Here's how it would work. The current behavior of "a:b(c)" would
not be changed at all, and in all situations where "a:b" currently
raises a syntax error - including "(a:b)(c)" - Lua would instead
generate code that would look for a metamethod "__colon" in the
metatable of a; when that metamethod is found, the result of "a:b"
would be this,

  getmetatable(a).__colon("b")

and when a doesn't have a metatable, or when a has a metatable but it
doesn't have a "__colon" field, Lua would just raise an error: "Colon
behavior not defined for <a>" - or it would look for a default action
in a global variable whose name we would have to decide - "__colon",
maybe?

Btw, here is a related idea (that got no responses):
  "Re: Multiple indexing (was: 'in' keyword today)"
  http://lua-users.org/lists/lua-l/2014-04/msg00544.html

and here's a link to some recent messages on ":" (april 2014 only):
  "Ideas about colon operator syntax (and a patch in the work)"
  http://lua-users.org/lists/lua-l/2014-04/threads.html#01318

Cheers,
  Eduardo Ochs
  eduardoochs@gmail.com
  http://angg.twu.net/