On Mon, May 19, 2008 at 12:01 AM, ddneilson <
ddneilson@gmail.com> wrote:
Miles Bader wrote:
ddneilson <ddneilson@gmail.com> writes:
I guess I just don't see how having inconsistent behaviour is desirable;
the behaviour being defined this way doesn't make it any less
inconsistent. function(...) pushes all of its return values onto the
stack; but, if you call another function before popping the stack then
you lose all but the first return value. Seems so very strange.
The current behavior is _much_ more predictable, because you can
trivially see what will happen by only looking at the call site (in the
source code). As a result, it's also far more robust.
I think this is a good illustration of how thoughtfully Lua is designed.
More predictable if you're already familiar with Lua, sure. However, if you're newly coming to Lua from other programming and don't neccessarily retain every word of the manual then it's a gotcha. ;-)
Note, I do think it would be nice if there an optional way to get the
"splicing" behavior you want, for those times when you know it's the
right thing.
E.g., some sort of "@splice ..." special-form which would tell the
compiler to keep all values:
fun1 (fun2(), @splice fun3(), @splice fun4(), fun5())
would keep only the first result of fun2, but would keep all results
from fun3, fun4, and fun5.
I really like this idea. Maintains backward compatibility, and adds useful additional functionality. Can anyone "in the know" comment on how difficult it would be to add something like this to the Lua compiler/interpreter?
-Daniel