[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Relational metamethods and mixed types
- From: Geoff Leyland <geoff_leyland@...>
- Date: Tue, 24 Mar 2009 13:03:51 +1300
Hi,
PiL says: "Unlike arithmetic metamethods, relational metamethods do
not support mixed types...".
Supporting mixed types would be very handy for defining constraints in
Linear Programs, where you could go:
a_constraint = 2 * x1 + 3 * x2 + 4 * x3 <= 6
Where the type of the result of the expression on the LHS is a list of
terms containing LP variables, and the type of the RHS is clearly a
number. Note that this isn't a statement about truth, testing or
ordering, it's a constraint on the values of xi to be respected while
solving an optimisation problem.
Unfortunately, I can't do this because the left and right-hand sides
aren't the same types.
The pure Lua alternative I can think of is to offer easy constructors
for term lists:
a_constraint = 2 * x1 + 3 * x2 + 4 * x3 <= make_term_list(6)
This isn't too onerous, but a better alternative would be nice.
Can anyone shed any light on:
- why there is a restriction on mixed-type relational metamethods
- whether the right place to patch this is around luaV_lessthan in
lvm.c
- whether there's anywhere else that would need to be patched -
particularly if there's other places in luajit
- whether anyone's code would break if mixed-type relational
metamethods were allowed
- whether there is any chance of allowing mixed-type relational
metamethods in a future Lua
Thanks in advance,
Geoff