[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Odd behaviour with multiple return values and varargs
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Thu, 13 Sep 2007 12:03:33 -0400
David Kastrup wrote:
>> The same argument can be used for what I am trying to do, only I
>> *have* to use temporary variables. What I was trying to do is:
>> function Position()
>> return x,y
>> function Dimensions()
>> return w,h
>> function push_clip(x,y,w,h)
>> -- Do stuff
>> push_clip(Position(), Dimensions())
> See how bad the idea is? Hide away the definition of Position and
> Dimensions, and you have _no_ clue whatsoever what arguments can be
> affected from "Dimensions". Worse: a bug in Position will clobber
> the relation between w, h, and Dimensions, leading to symptoms in an
> area completely unrelated to the actual bug.
The same is true for the last argument of the list. Example:
function logerror(msg, fatal)
if fatal then os.exit(fatal)
-- And then someone convert getlasterror from:
function getlasterror() return strerror(errno) end
function getlasterror() return strerror(errno), errno end
-- and your program starts exiting unexpectedly.
So far the only real argument in favor of truncation on that discussion
is that it's an implementation limitation. All other arguments are
either irrelevant (a matter of personnal preference) or applicable to
the last argument too.
The fact is that the special treatment for the last argument is an
inconsistency. Also, if we had no truncation (that's an interpreter
change, not a syntax change), it would be possible to force truncation
(with extra parentheses), whereas now, with truncation enabled, you
cannot prevent it.
I personnaly prefer the way it works now, but it's neither logical nor
natural, it's clearly a Lua-ism.