[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    Re: Syntactic sugar for references
From:       Sam Pagenkopf <ssaammp () gmail ! com>
Date:       2019-06-24 16:14:17
Message-ID: CAKiGDcM=xuG90tfFxcfQXteH39+ocsetdr4iw_==8EBA1Uf9JQ () mail ! gmail ! com
[Download RAW message or body]

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

[Attachment #3 (text/html)]

<div dir="auto"><div dir="auto">A short &quot;closure&quot; syntax can be implemented \
in languages that compile to Lua, like moonscript. you might also want to try \
JavaScript.</div><div dir="auto"><br></div>Lua doesn&#39;t have references at all. \
you can do  <div dir="auto"><br></div><div dir="auto">function (t) t.x = value \
end</div><div dir="auto"><br></div><div dir="auto">to set values &quot;by index&quot; \
(my words) rather than by reference. there&#39;s often a better solution than just \
emulating references.</div><div dir="auto"><br></div></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 24, 2019, 3:48 AM \
Moorea Moorea &lt;<a href="mailto:moorea@ymail.com" rel="noreferrer noreferrer" \
target="_blank">moorea@ymail.com</a>&gt; wrote:<br></div><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">Hi there,<br> <br>
I&#39;ve read a few faq, stackoverflow, even cool stuff like<br>
<a href="http://lua-users.org/wiki/ShortAnonymousFunctions" rel="noreferrer \
noreferrer noreferrer noreferrer" \
target="_blank">http://lua-users.org/wiki/ShortAnonymousFunctions</a><br> <br>
I&#39;m new to LUA (which I&#39;m sure this email/ideas will make obvious even \
without me disclosing so)<br> <br>
And I was wondering what is the thinking around adding some syntactic sugar around \
shorter lambdas that would still capture the right scope<br> <br>
something like<br>
      (y){return 42+x+y}    <br>
instead of  <br>
      function(y) return 42+x+y end<br>
<br>
and also something like<br>
<br>
function foo(&amp;x)<br>
      &amp;x = 42<br>
end<br>
<br>
local y<br>
<br>
foo(&amp;y)<br>
<br>
print(y) -- prints 42<br>
<br>
where &amp;y is replaced (in caller) by<br>
   function(res) y = res end<br>
and &amp;x is replaced in the callee body by<br>
     &amp;x = 42 -&gt; x(42)<br>
<br>
(ie it works)<br>
<br>
Thanks for your input or pointers to how to do that or why it&#39;s bad<br>
(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)<br> <br>
--<br>
MooreaTv<br>
<br>
    <br>
<br>
</blockquote></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic