lua-users home
lua-l archive

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


> 2)
> Frequently both quotient and remainder are needed.
> Let % operator returns pair of values:
> a % b == a-floor(a/b)*b, floor(a/b)

+1 on this. It is now a long time I'm thinking to propose the same
thing but not in the
form of operator % but as a function math.div. This function is very
useful, it does already exist in the standard c library and (I guess)
it is very inefficient if implemented in Lua.

For the other side for me is confusing an operator that returns two
values so I was thinking to a function instead.

> 3)
> Lua lacks fast function to build initialized
> array.  A function like this will be useful
> if implemented in C:
>
> function table.new(size, value)
>   value = value or 0
>   local t = {}
>   for i = 1, size do
>     t[i] = (type(value)=='function')
>            and value(i) or value
>   end
>   return t
> end

+1 also on this. I've implemented also this in gsl shell but it is
done in plain Lua :-)

> 5)
> Syntactic sugar needed for primitive equality.
> Let a===b denotes rawequal(a,b)
> Inspired by Smalltalk :)

no please :-) it's a matter of taste but I really dislike the three
equal operator.

> 6)
> Why equality operator is so special in Lua?
> Any string or any number is always not equal
> to any table despite of __eq field in metatable.
> Example: it is impossible to implement rational
> numbers in nice manner:
>   local r = rationalNumber '1/12'
>   r = '2/3' - 2*r            -- ok
>   assert(r >  '1/3')         -- ok
>   assert(r >= '1/2')         -- ok
>   assert(r <= '1/2')         -- ok
>   assert(r == '1/2')         -- never
>   -- a blot on the landscape  :(

Seems to be logical but the == operator is so important for the
language that I'm wondering if you can overload it without
unpredictable side effects...

Francesco