lua-users home
lua-l archive

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

Hello Volodymyr,

what if the called function has a desired side effect?

Something similar to
pos = file:seek( 1000, "set")
print ("position is:", pos)

which value for pos would you expect, and which do you get?

Hi Lua lovers!

Here's an idea and i hope we can have some kind of lazyness in Lua.

The proposed syntax and semantics follows:

1) Lazy variables are kind of local variables. Though, their value is not calculated until it actually needed, after that they start acting as usual local variables. So, some_function() will not be called until you use the variable l value:

lazy l = some_function(arg1, arg2)-- some_function() not called yet

-- some_function() called and result is used, l starts to be usual var
local l_twice = 2 * l
-- some_function() not called, previously calculated result is used
local l_thrice = 3 * l