lua-users home
lua-l archive

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


On Wed, Sep 27, 2006 at 06:33:24PM -0500, Rici Lake wrote:
> The fact that you happily program in Lua without being aware of the ^ 
> operator demonstrates, I think, that extra operators do not necessarily 
> get in your way, don't you think?

It demonstrates that I currently write and maintain my own Lua code,
and nobody else's.  I don't expect that will be the case forever.
It'd be likely to get in my way if, for example, I wanted to port
LuaJIT to another architecture.

> >But you missed the second half of my sentence: what about math.min,
> >max, abs?  All things that a bignum implementation would want to
> >overload.  Why don't they get operators, too?  Complex or rational
> >number types would want to overload most of math.
> 
> Yes, it's hard to know precisely where to draw the line. I don't think 
> max and min are math operations, myself (they certainly apply to 
> strings), and if max and min were added as operators (or inf and sup), 
> I probably wouldn't object, but see below.

Well, more generally min and max should be implemented in terms of
the < operator, so they'd never actually need overloading except
as an optimization.  (But I don't see any need for them to be
operators.)  But the complex and rational cases are better examples;
every math function is a useful overload.

> It's a balance which
> includes convenience, esthetics, and (yes) efficiency, and we
> would probably each draw the line at a different point.

The fact that Lua is at 5.1 and still as lean as it is gives me hope
that, oddball % operator notwithstanding, the Lua folks draw the
line pretty high.

> As far as "another metamethod to overload", that's no different
> from "another library method to overload", as far as I can see.

The core knows about the metamethod; it knows nothing about simple
library methods.

> Contrary to the (incorrect) subject of this message, I'm not
> one of the people pushing for bitstring operators. If bitstrings
> were a fundamental type in Lua, then most of the common bitwise
> operations could be assigned to other existing operators; other
> ones could be library functions or whatever. But bitstrings are
> not a fundamental type in Lua, and, however useful they may be

This is why % and // seem out of place to me; integers are not a
fundamental type in Lua, only numbers are.  (Granted, % is defined
for floating point numbers, but I have no idea what use it has and
its primary use seems intended to be integers.)

In case anyone's wondering, my own pet operator is unary +.  I have
a lot of coordinates specified in Lua expressions, and I hate having
to write "10, -10" instead of "+10, -10".  It doesn't even add
anything to the VM, just parse it out and treat it as a no-op.  (This
one feels like something basic and fundamental missing from the
language to me, where none of the others have.)

-- 
Glenn Maynard