[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [NoW] Once more about to-be-closed variables
- From: Sergey Kovalev <kovserg33@...>
- Date: Fri, 12 Jul 2019 08:52:04 +0300
пт, 12 июл. 2019 г. в 00:10, Egor Skriptunoff <egor.skriptunoff@gmail.com>:
>
> On Thu, Jul 4, 2019 at 3:43 PM Sergey Kovalev wrote:
>>
>> Yes indeed. There is no pure function in lua. That's why they are quite rate.
>> upvalues are almost everywhere that's we are unable to isolate
>> different part of code.
>>
>
>
> Nested scopes (with ability to access variables/functions from outer scope but not from inner) is a useful feature.
> Nested scopes was a strong argument in "Pascal vs. C" holywars, and I was very proud to be at Pascal side :-)
>
> Lua programmers are using upvalues frequently because upvalues are powerful; that's why pure functions are rare in Lua.
Upvalues are powerful but some times you need ability to isolate one
part of code from another. The ability to isolate all upvalues in some
scopes could be very handful.
fn=pure_function(args)
body -- here all upvalues deined outsize is absent
end
Now it could be achieved only using load function.
https://raw.githubusercontent.com/kov-serg/lua-aux/master/pure.lua
But this method is unable to force declare all variables used
explicitly. Instead it could return all "global" variable it change.
Another side effects are in modules:
[ex1.lua]
print("x",x)
[main.lua]
x=1 require "ex1"
package.loaded.ex1=nil
x=2 require "ex1"
Such sides effects could be headache in big projects. Because result
will depend from order of requires. Instead modules should be defines
in isolated environments.
The ability to localize or prevent side effects could be more useful
than badly thought-out toclose syntax.
- References:
- [NoW] Once more about to-be-closed variables, Egor Skriptunoff
- Re: [NoW] Once more about to-be-closed variables, Sean Conner
- Re: [NoW] Once more about to-be-closed variables, Egor Skriptunoff
- Re: [NoW] Once more about to-be-closed variables, Sean Conner
- Re: [NoW] Once more about to-be-closed variables, Egor Skriptunoff
- Re: [NoW] Once more about to-be-closed variables, Dirk Laurie
- Re: [NoW] Once more about to-be-closed variables, Egor Skriptunoff
- Re: [NoW] Once more about to-be-closed variables, Sergey Kovalev
- Re: [NoW] Once more about to-be-closed variables, Egor Skriptunoff
- Re: [NoW] Once more about to-be-closed variables, Sergey Kovalev
- Re: [NoW] Once more about to-be-closed variables, Egor Skriptunoff