lua-users home
lua-l archive

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

On 11/26/2010 05:58 PM, Pierre-Yves Gérardy wrote:
On Fri, Nov 26, 2010 at 23:49, Doug Lua<>  wrote:
  \x,y,z(x*y+z)    -->  function(x,y,z) return x*y+z end

It's concise and seems to have the fewest (zero?) ambiguities.
It doesn't support statements. Just one expression list to be
returned. It's useless if you want to use it for delayed execution of
code blocks.

Yes, this form would not be good for more complex functions requiring control structures. I think the normal Lua function form is perfect in that case - it already gives you everything that Lua has to give. If you're looking for lazy evaluation, that's a different discussion. It's a worthwhile discussion, just not the one I'm having here at the moment.

This branch of the discussion was about short forms for returning expressions. See my sentence that you did not copy ("If the form is to be limited to an expression..."), and the very first bulleted item in phlnc8's Rationale section ("keep it simple: no statement, no block, just an expression...").

But as long as we're discussing it, the form could easily be modified to require 'return', which would then allow it to include any other control structures:

  \x,y,z(return x*y+z)    -- Or the more complex...
  \x,y,z(if x > 0 then return x*y+z else return 0 end)

But the brevity is lost, and the brevity is what is so appealing in the situations where arithmetic expressions are to be passed to other functions for later evaluation.