[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Things not to add to Lua (slices) [was: table insertion]
- From: David Given <dg@...>
- Date: Fri, 5 Nov 2004 11:15:04 +0000
On Friday 05 November 2004 01:48, Mike Pall wrote:
> Since you mentioned Python, I can back this up with statistics:
I'm sorry! I'm sorry! I didn't mean it! I should have known better than to
mention Python here!
Seriously, it's very interesting to see actual numbers. I didn't realise the
slice stuff was so infrequently used; you're right, it makes very little
sense to use opcodes. Do you have the full list anywhere? Has anybody done
any similar analysis for Lua?
There is, however, one remaining argument for using syntax for slices that you
haven't demolished: it's very nice to be able to use the same syntax for
l-values and r-values.
dest[:] = source[:] (in Python)
The Lua equivalent would have to be:
table.setslice(dest, 1, -1, table.getslice(source, 1, -1))
...which is much less pretty.
Hmm... thinking about the best way of doing this in Lua style, I think that
probably extending your table.move() would fit better:
table.move(desttable, deststart, destend, srctable, srcstart, srcend)
i.e. you give it the source and destination tables and the slices therein.
Source and destination could be the same, of course. Let srcstart and srcend
default to all of srctable, and the above becomes:
table.move(dest, 1, -1, source)
(1, 0) would insert and (0, 0) would append. This would avoid the need for any
new syntax for slices, or any new opcodes, would be in keeping with the Lua
philosophy as well as being much easier to optimise and not require any new
programming concepts. I hereby withdraw my suggestion. Fast,
non-function-call array append and length would still be handy, though.
(The OO theoretician in me cringes at the idea of an operation on one table
changing the contents of another, but that's how Lua does practically *all*
non-trivial table operations...)
> Lesson #4. Please keep that in mind when the recurring 'we need tuples
> for Lua' thread comes around again.
Yeah, but let's hope it doesn't.
+- David Given --McQ-+ "I must have spent at least ten minutes out of my
| email@example.com | life talking to this joker like he was a sane
| (firstname.lastname@example.org) | person. I want a refund." --- Louann Miller, on
+- www.cowlark.com --+ rasfw