lua-users home
lua-l archive

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

On Friday, December 19, 2014 07:46:08 PM steve donovan wrote:
> Can't help feeling that memoization gets us most of the benefits
> without new syntax/semantics.

Which is fine if you only access a variable through a function interface. If 
you want to pass something by-value you're forced to evaluate it at call time 
as opposed to use time. i.e

    function one_or_the_other(alpha, omega)
      if some_condition() then

    alpha = lazy(function() return calculate_alpha() end)
    omega = lazy(function() return calculate_omega() end)
    one_or_the_other(alpha, omega)

In this situation 'calculate_omega' would never be called if the condition is 
true. The 'one_or_the_other' function doesn't have to know that the value is 
evaluated late.

tom <>