lua-users home
lua-l archive

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


A short "closure" syntax can be implemented in languages that compile to Lua, like moonscript. you might also want to try _javascript_.

Lua doesn't have references at all. you can do 

function (t) t.x = value end

to set values "by index" (my words) rather than by reference. there's often a better solution than just emulating references.


On Mon, Jun 24, 2019, 3:48 AM Moorea Moorea <moorea@ymail.com> wrote:
Hi there,

I've read a few faq, stackoverflow, even cool stuff like
http://lua-users.org/wiki/ShortAnonymousFunctions

I'm new to LUA (which I'm sure this email/ideas will make obvious even without me disclosing so)

And I was wondering what is the thinking around adding some syntactic sugar around shorter lambdas that would still capture the right scope

something like
    (y){return 42+x+y}  
instead of 
    function(y) return 42+x+y end

and also something like

function foo(&x)
    &x = 42
end

local y

foo(&y)

print(y) -- prints 42

where &y is replaced (in caller) by
  function(res) y = res end
and &x is replaced in the callee body by
   &x = 42 -> x(42)

(ie it works)

Thanks for your input or pointers to how to do that or why it's bad
(I am aware the standard ways to change caller state is pass a table in, or return multiple values; but neither of those work within expressions for instance)

--
MooreaTv