lua-users home
lua-l archive

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


I really dont want to be suggesting a 3rd option, but how about returning the only thing that the caller doesn't explicitly provide, namely the index assigned to the thing being inserted.

(The thing-ists out there could be satisfied by having it return index, thing, but maybe that's getting far too crazy)

Daniel.


On 12/20/09 7:36 AM, frank wrote:
Ico wrote:
* On 2009-12-20 frank <frank@frankhirsch.net> wrote  :
[...]
Giving back the table as return value from table.insert would:
 - enable "sometable=table.insert(sometable or {},newelement)"
 - not break existing code
 - probably not significantly impact performance

So, why not?

I guess the other 'logical' behaviour would be to return the newly
inserted element instead of the table:

  thing = table.insert(sometable, new_thing())

Maybe neither is implemented because they're both equaly logical ?

Even without arguing which possibility feels more natural, if the
performance impact is as low as I imagine (very nearly none) then
it would make sense to return whichever instead of neither.

So I submit to establish the feasibility to return a value first,
and commence the argument over what should be returned second... =)

Regards, Frank