lua-users home
lua-l archive

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


It will not surprise people. They will use functions as before. "pure_function" is additional feature for special cases
It could isolate possible side effects, due to miss typing or forget to define local variable or any other reasons.
Moreover it could be combined with common function to achieve different aims.
The simples way is

pure_function fn(args)
-- ...
end

converted into something like this

isolate_all_upvalues(args, -- somehow remove all upvalues
function fn(_ENV,args)
-- ...
end)


пт, 5 апр. 2019 г. в 14:00, <lua-l-request@lists.lua.org>:
Send lua-l mailing list submissions to
        lua-l@lists.lua.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/lua-l-lists.lua.org

or, via email, send a message with subject or body 'help' to
        lua-l-request@lists.lua.org

You can reach the person managing the list at
        lua-l-owner@lists.lua.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of lua-l digest..."


Today's Topics:

   1. Re: New feature for lua (steve donovan)


----------------------------------------------------------------------

Message: 1
Date: Fri, 5 Apr 2019 08:30:24 +0200
From: steve donovan <steve.j.donovan@gmail.com>
Subject: Re: New feature for lua
To: Lua mailing list <lua-l@lists.lua.org>
Message-ID:
        <CA+ZMS_vvPG4pri18qwsvbRtYd0XXn7G90Nd_3A1grPoq7Zhomw@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"

On Fri, Apr 5, 2019 at 8:12 AM Sergey Kovalev <kovserg33@gmail.com> wrote:
>
> Let inroduce new reserved word "pure_function" into lua.
> It should work similar to usual function except
> all variables used inside are implicitly local
> no access to any upvalues or global namespace _G
> So it could interact with arguments it was passed.

The 'implicitly local' bit will be a surprise to people, I think.
Global-as-default has mostly served us well.

I'm wondering if this could not be done just as a check using bytecode
- i.e. annotate a function as 'pure' in some way and look at the
bytecode to see if it has any upvalues or globals referenced.



------------------------------

_______________________________________________
lua-l mailing list
lua-l@lists.lua.org
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/lua-l-lists.lua.org


End of lua-l Digest, Vol 105, Issue 12
**************************************