lua-users home
lua-l archive

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


ddneilson <ddneilson@gmail.com> writes:
>> 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. ;-)

No, more predictable, period.  Because Lua doesn't have function
declarations, nor do Lua functions have a fixed number of return values,
you can't tell how many return values there will be without seeing (and
understanding -- think "halting problem"...) the source code to the
called function and in many cases, functions _it_ calls (because tail
calls propagate all return values).

For the tail position this is basically manageable, as adding additional
arguments at the end usually has either no effect, or is expected [if
it's a varargs-type function].  But in the middle of the argument list,
it's much less likely to be OK [if it was "varargs" case, you might want
splicing, but in other cases, propagating an unexpected return value
completely messes up the meaning of all following arguments].

>> 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?

-Miles

-- 
P.S.  All information contained in the above letter is false,
      for reasons of military security.