lua-users home
lua-l archive

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

On 12 Sep 2006, at 12:11, Tomas wrote:

Actually no-one was arguing it should go faster, merely that it should be easier to type. There are two legitimate concerns as I see it:

1) when t is a long name. Could be particularly embarrassing if you misspell it (personally I don't like long names, but hey)
	The problem is not with the operation, but with the name of the
table. If it bothers you why don't you simply change it to a short one?

2) when t is a more complex expression, eg: f(x)[#? + 1] = value.
	The problem here is not with the append operation also.  It shouldn't
be clear/legible to separate the "more complex expression" into two small
and readable ones?  Something like: local t=f(x); t[#t+1]=value
	In both cases I think the discussion is diverging to a kind of
competition of tastes: "I prefer this" X "I prefer that" :-(

I'm always very loath to suggest or support more syntax, but how about if '#' on its on in an expression inside [] were to mean the length of the table being indexed. So you could go:

t[#+1] = value

It's pretty clear, and almost syntactically unambiguous.
	And one-character less (to use this subjective argument) than
the current (and I think unquestionably legible, clear, unambigous...):

t[#t+1] = value

Well, the likes of you and me always use 1 character variable names, and we always introduce new variables for complex sub-expressions, so on the whole I'm inclined to agree with you. But Lua already supports many style of programming, I was just recognising the needs of others.

Of course, if arrays were habitually indexed from 0 and the semantics of '#' changed accordingly then append would simply be:

t[#t] = value, and no-one would be complaining.

Personally, I don't like ':' as in a:b() to which your arguments also apply.