Re: lua-l Digest, Vol 105, Issue 12

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: lua-l Digest, Vol 105, Issue 12

Sergey Kovalev
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, <[hidden email]>:
Send lua-l mailing list submissions to
        [hidden email]

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
        [hidden email]

You can reach the person managing the list at
        [hidden email]

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 <[hidden email]>
Subject: Re: New feature for lua
To: Lua mailing list <[hidden email]>
Message-ID:
        <[hidden email]>
Content-Type: text/plain; charset="UTF-8"

On Fri, Apr 5, 2019 at 8:12 AM Sergey Kovalev <[hidden email]> 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
[hidden email]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/lua-l-lists.lua.org


End of lua-l Digest, Vol 105, Issue 12
**************************************
Reply | Threaded
Open this post in threaded view
|

Re: lua-l Digest, Vol 105, Issue 12

Sean Conner
It was thus said that the Great Sergey Kovalev once stated:
> 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.

  I use luacheck to prevent typos and forgetting to define local variables.
Running luacheck over this:

function fromjulianday(jd)
  a = jd + 32044
  b = (4 * a + 3) // 146097
  c = a - (b * 146097) // 4
  d = (4 * c + 3) // 1461
  e = c - (1461 * d) // 4
  m = (5 * e + 2) // 153

  return {
    day   = e - (153 * m + 2) // 5 + 1,
    month = m + 3 - 12 * (m // 10),
    year  = b * 100 + d - 4800 + m // 10
  }
end

produces

Checking jd.lua                                    21 warnings

    jd.lua:1:10: setting non-standard global variable fromjulianday
    jd.lua:2:3: setting non-standard global variable a
    jd.lua:3:3: setting non-standard global variable b
    jd.lua:3:12: accessing undefined variable a
    jd.lua:4:3: setting non-standard global variable c
    jd.lua:4:7: accessing undefined variable a
    jd.lua:4:12: accessing undefined variable b
    jd.lua:5:3: setting non-standard global variable d
    jd.lua:5:12: accessing undefined variable c
    jd.lua:6:3: setting non-standard global variable e
    jd.lua:6:7: accessing undefined variable c
    jd.lua:6:19: accessing undefined variable d
    jd.lua:7:3: setting non-standard global variable m
    jd.lua:7:12: accessing undefined variable e
    jd.lua:10:13: accessing undefined variable e
    jd.lua:10:24: accessing undefined variable m
    jd.lua:11:13: accessing undefined variable m
    jd.lua:11:27: accessing undefined variable m
    jd.lua:12:13: accessing undefined variable b
    jd.lua:12:23: accessing undefined variable d
    jd.lua:12:34: accessing undefined variable m

  I'm not aware of any tool that can check for global usage, but something
like luacheck could probably be written to report global and upvalue usage
by function.  

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

  Could you give a better example of this?  I'm not following the example
given.  Are you just collecting any upvalues into a custom environment for a
function?  

  -spc