lua-users home
lua-l archive

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


On Wed, Sep 27, 2006 at 04:24:23PM -0500, Rici Lake wrote:
> >This applies to every operation.  pow() is no more cleanly overridable,
> >or any of the myriad of operations a bignum class would want to 
> >implement.
> >This isn't an argument for div and mod in particular.
> 
> yes it is. just set the __pow metamethod.

(I didn't even know Lua had a ^ operator.  Eh.)

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.

> >That said, I thought all types could have a metatable in 5.1, and it
> >seemed like numbers would be set to the "math" table, but I get:
> >
> >=getmetatable(2)
> >nil

(Aside: it works fine, actually, the metatable just isn't set by
lmathlib.c like it is by lstrlib.c.)

> function quad(a, b, c)
>   return b:neg():plus((b:squared()
>                        :minus((4):times(a):times(c)))
>                        :sqrt())
>           :div(2):div(a)
> end

(According to this little reduction-to-absurd, every function
should be an operator, and suggesting that any function should
not be an operator leads to absurdity.  That's, well, sort of
absurd ...)

My response stands unchanged: things can be overloaded without
having to add a whole operator to the language.   You said that
you wanted an operator so you could overload it, and I pointed
out that you don't need an operator for that.

> The question of "what belongs in a library" doesn't have absolute
> answers, I don't think. How much does adding % bloat the language?
> Maybe 200 bytes. Is it worth the inconvenience of a library call to
> save 200 bytes? That's in the eye of the beholder, I would say. All
> of those 200 bytes do add up.

It adds up in the net complexity of the language: another operator
for everyone to understand, another metamethod to overload it, another
operator to define precedence for.  I think it adds up very quickly.

-- 
Glenn Maynard