lua-users home
lua-l archive

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

пт, 12 июл. 2019 г. в 00:10, Egor Skriptunoff <>:
> 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.

  body -- here all upvalues deined outsize is absent
Now it could be achieved only using load function.
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:

x=1 require "ex1"
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.