lua-users home
lua-l archive

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


PA wrote:
[...]
> _ = aTable + "one"

Aaargh, no!

*cough* Sorry, let me rephrase: I would very strongly advise not doing that...
using + as an infix operator implies that the original value is not being
modified, and that instead a new value is being returned. Adding side effects
would be, to put it mildly, abusing the semantics.

You could define + as:

function table:__add(t, v)
  local newt = {}
  for i, j in ipairs(t) do newt[i] = j end
  newt[#newt+1] = v
  return newt
end

...though; this would allow:

aTable = aTable + "one"
aTable = aTable + "two"
aTable = aTable + "three"

Slowly, of course. However, this would allow any hypothetical += operator to
be optimised to do what we want quickly and efficiently and not require any
further syntax or semantics changes...

-- 
+- David Given --McQ-+ "Gaping from its single obling socket was
|  dg@cowlark.com    | scintillating, many fauceted scarlet emerald..."
| (dg@tao-group.com) | --- Jim Theis, _The Eye of Argon_ (spelling
+- www.cowlark.com --+ original)


Attachment: signature.asc
Description: OpenPGP digital signature