lua-users home
lua-l archive

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


I like the use of a simple operator,  but I'm also a bit unconfortable with the "*" choice.  In my opinion it gets too close to math operations.

May I ask what would be of the corresponding "*" metamethod? Assuming A and B were proxy tables with "__mul" handlers, what would "A*B" mean? A syntax error? A call to the handler?

Rici's choice of "#" is indeed interesting. The grid like format of # could also serve as a hint of it's use as a dimensional operator, even in situations such as

x, y = #world 

where "world" would be a two dimensional array with x * y (x times y) elements.

Concerning the use of the operator to strings and other types, maybe that could be solved with a "__dim" (from dimensions) metamethod?

Remember, when it comes to operators "size doesn't matter, it is the metamethod that counts"... :o)

Andre




On Thu, 04 Nov 2004 14:52:16 -0200, Roberto Ierusalimschy <roberto@inf.puc-rio.br> escreveu:

> De: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
> Data: Thu, 04 Nov 2004 14:52:16 -0200
> Para: Lua list <lua@bazar2.conectiva.com.br>
> Assunto: Re: table insertion [was: Lua 5.1 (work2) now available] 
> 
> > Whatever operator is used to return the "length" of a table, it would
> > be nice if it also could return the length of a string.
> 
> Sure.
> 
> 
> > "*" does not strike me as intuitive for an operator yielding the length
> > of a table. "#" would make more sense to me, but see below.
> 
> We thought about '#' first. But '*' is smaller :)
> 
> 
> > Any background, why '*' was regarded best..?
> 
> It is a common prefix operator; the character is already used in Lua;
> and some other languages use it as a length operator (e.g., Icon uses it
> as string length operator). And it is smaller than '#' :)
> 
> -- Roberto
> 
> 
> 
>