lua-users home
lua-l archive

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


On Mon, Sep 11, 2006 at 01:12:23PM -0700, gary ng wrote:
> > Not if you do it once. If you have identified the
> > time spent appending
> > to tables as being significant in your app, cutting
> > that time by 20%
> > would be a major coup!

> Does it worth it to be part of the language just for
> the 25% gain ?

No, not necessarily.

> I would buy it if we are talking about 5x and it really is used a lot.

I think its border-line weird to do

  atable[] = "to put at end" -- appends to atable!
  
That said, I do find it reminiscent of the auto-indexing in table
initializers:

	> t = { "a", "b", "c" }
	> print(t[3])
	c

I would like a way to be able to do

  t = {}
  t.push("on back")
  t.pop() => "on back"
  t.shift("on front")
  t.unshift() => "on front"

But you may be seeing my ruby-loving side showing. I like OO access, and
think having to do

  table.insert(a_table, "arg")

Is fairly painful for a common operation. Lua doesn't need

  atable[4] => ...

either, it could have been

  table.retrieve(atable, 4) => ....

But I'm glad its not! If there was a shift operator (<<), that could
be overloaded to mean "append" through the metatables:

  atable << "at end"

But, no shift operators in lua, sadly.

Sam