lua-users home
lua-l archive

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


Hi,

On 01/06/10 21:52, Petite Abeille wrote:
What about __add?
> E.g.:
>
> local function Add( aList, aValue )
>      if type( aValue ) == 'table' then
>          for anIndex = 1, #aValue do
>              aList[ #aList + 1 ] = aValue[ anIndex ]
>          end
>      else
>          aList[ #aList + 1 ] = aValue
>      end
>
>      return aList
> end

IMHO it is unexpected behaviour that the operator '+' modifies it's arguments. Usually operator '+' creates a new value from it's arguments, whereas operator '<<' makes it more clearly, that something is going from right to left and probably modifying the left argument. '+' is more symmetric that '<<', i.e. '+' should treat it's both arguments the same.


aList = aList + { 'a', 'b', 'c'} + 'f' + { 'x', 'y' } + 'z'

I thougt you may omit "aList =" here, but I tried it and lua complains for syntacatical reasons ;-)

So at least

> aList = aList + { 'a', 'b', 'c'} + 'f' + { 'x', 'y' } + 'z'

would give the same result when printing aList than

> local x = aList + { 'a', 'b', 'c'} + 'f' + { 'x', 'y' } + 'z'

So x points to the same table than aList, not very intuitive I think.

Beste regards,
Oliver