lua-users home
lua-l archive

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


Mike Pall wrote:

...
Lua uses the 'pure' definition for object comparison: there is no
ordering relationship between objects of different types. This is
in line with the Lua definition of object equality as object identity.
So from a language design standpoint this is very consistent.

Because when you allow SFFloat(5.2) < 4.7, then you really should make
SFFloat(5.2) == 5.2 return a true result, too (difficult, but doable
with automatic type coercion). But then you better ensure that
table[SFFloat(5.2)] does the same as table[5.2]. This is where you get
into real trouble (we had a similar discussion a few weeks ago).

Umm, and automatic type coercion is troublesome, anyway -- have
a look at the implementation of some languages that do this.
I personally dislike the implicit string/number coercions in Lua,
too (but I guess this is a convenience vs. purity issue).

[And I have to add, that for my next bigger project (to be released
 soon) the 'pure' language definition of Lua makes things an order
 of magnitude easier.]

So to summarize: the standard Lua operators won't help you here.
Either use only canonical types or define your own operators,
e.g. lt(SFFloat(5.2), 4.7). You loose the infix syntax, but
you'll get used to it.

But those same arguments are true for the arithmetic operators, yet Lua supports those operators for different types. For instance:

    local a = SFFloat(4.5) * 5.2

works just fine. And on the subject of "purity", I can agree that disallowing string vs. number comparisons is a reasonable (although, in my opinion, unnecessary) constraint. But when dealing with user defined types that distinction becomes more grey. In my case, what Lua sees as a userdata, I see as a number.

I'm not asking Lua to have a type coercion system, just that the equality operators behave like the arithmetic ones. I guess I don't understand why they are treated differently.

FYI, I patched 5.02 to have luaV_lessthan() and luaV_lessequal() behave like Arith, and everything now works for me. I suppose I can patch the releases as they come out.

Thanks.

PS - I has been years since anyone has complained about my sig. Back in the days when people were using 1200 baud modems those 12 lines made a big difference in download time! But I never got accused of being a script kiddie. It makes me feel so young :-) If you use a fixed pitch font and squint, you will see that it is just my first name in script. Sorry about the inconvenience. I will try to remember to delete it after this message (to accomodate any squinters reading this) :-)

--
chris marrin                ,""$,
cmarrin@arch.sel.sony.com b`    $                             ,,.
(408) 955-3049          mP     b'                            , 1$'
Sony    ,.`           ,b`    ,`                              :$$'
     ,|`             mP    ,`                                       ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'