lua-users home
lua-l archive

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


On Thursday 04 November 2004 15:08, Roberto Ierusalimschy wrote:
[...]
> I have a proposal for a new operator (after all these years): "*t" would
> return the "size" of table t. With that operator, the insertion of a new
> element in an array would be written as <<t[*t+1] = v>>. To remove the
> last element, we would write <<t[*t] = nil>>.

I quite like this, but I'm not keen on the new operator.

In a lot of ways, Lua's greatest strength (objects are tables) is also its 
greatest weakness (tables are objects). It means that we can't use OO syntax 
to manipulate tables. We can't use t.length to return the length of the table 
because it conflicts with trying to fetch the 'length' field...

Currently, using a new operator is probably the best solution, because it 
makes it clear that the operation is not calling a function (which a 
pseudofunction like length(t) would not). But, is there a better way of 
solving the underlying problem? Might it not be worth finally biting the 
bullet and distinguishing between field lookups and method calls?

(BTW, would this work via a metatable operation? Could you virtualise it?)

-- 
+- David Given --McQ-+ (base 10) = (base pi)
|  dg@cowlark.com    | 1 = 1; 2 = 2; 3 = 3
| (dg@tao-group.com) | 3.1415926... = 10.0
+- www.cowlark.com --+ 4 = 12.201220211...