lua-users home
lua-l archive

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


Quoth Steve Litt <slitt@troubleshooters.com>, on 2011-02-04 00:49:29 -0500:
> Notice nextt.fname. That's not my intent, and I understand it should give me 
> wrong results, but why should it be a compile time error? Whereas nextt.lname 
> runs as expected, nextt.fname throws the following error:
> =================
> slitt@mydesk:/d/at/htmlslides_data/leap_lua$ ./tableproblem.lua 
> /usr/bin/lua: ./tableproblem.lua:20: attempt to index local 'thiss' (a nil 
> value)
> stack traceback:
>         ./tableproblem.lua:20: in function <./tableproblem.lua:14>
>         [C]: in function 'sort'
>         ./tableproblem.lua:28: in main chunk
>         [C]: ?
> slitt@mydesk:/d/at/htmlslides_data/leap_lua$
> =================

I'm guessing this is because your comparison function is inconsistent.
If a comparison function gives logically inconsistent results, sort
can go haywire trying to rearrange the array, and then it may wind up
pulling out nils (I think).  Generalized sorts tend not to be written
to try to detect inconsistent comparison functions because this is
awkward in the general case, slows everything down, the results are
usually not meaningful anyway, and usually the best you could do would
be raise a slightly less confusing error.

And it's not a "compile-time" error; it's being raised at runtime when
your comparison function is invoked with a nil as the 'thiss'
argument.  Place a print('foo') before the sort invocation and you
should see that it happens before the error.

   ---> Drake Wilson