lua-users home
lua-l archive

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


Andy Stark wrote:
An alternative to assignment operators (+=, etc) might be to have a
shorthand for referring to the variables on the left hand side of the
assignment. Perhaps one of the unused characters (question mark, say)
could be used for this. So if we started with:-

   longVarName = longVarName + 1

...we could change it to:-

   longVarName = ? + 1

...and then perhaps ?1, ?2, etc for multiple assignments.

Some time ago, I wrote a patch for Lua which does this (except with
$ instead of ?), which I think is floating around in various places
(not on LuaPowerPatches, though, because I'm not really sure I like
it either.) If you want to play with it (and it comes with absolutely
no guarantees), you can find it at:

http://primero.ricilake.net/lua/pseudo-5.1.2.patch

Note: in a multiple assignment, $ refers to the matching lhs, and $i
refers to the i'th lhs. I'm not certain that the "matching lhs" rule
is correct: it's been suggested that $ should refer to the list of
lhs's, so that you could do a sort of rotate:

  a[x], a[x+1], a[x+2] = $3, $

That indeed might be convenient but right now you'd have to write:

  a[x], a[x+1], a[x+2] = $3, $1, $2

With this notation, ++ can be expressed almost as concisely:

  a[x] =$+ 1

and you can write expressions hard to write in C++, such as:

  a[x] = 2 * $ + 1

  a[x] = func($)

etc.

It does have a certain something going for it....