[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Delayed evaluation of expressions
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Fri, 1 Jul 2011 12:36:30 +0200
2011/7/1 steve donovan <steve.j.donovan@gmail.com>:
> On Fri, Jul 1, 2011 at 7:16 AM, Lorenzo Donati
> <lorenzodonatibz@interfree.it> wrote:
>> What I wonder now is whether the possibility of delaying the evaluation of
>> an expression would be useful also in other contexts.
>
> Well, we already have such a mechanism - function() return
> delayed_fun(something) end. Some have felt that this feels over-wordy,
> so that ends up in the 'short function form' discussion meme[1].
So far everyone seem to answer these kind of requests (delayed
evaluation of function parameters) with solution based on one form of
"explicit closure creation". In other languages, there are
alternatives which I'd call "implicit closure creation". For example
in Scala, there is a "by-name" parameter passing mechanism. In
essence, the function itself declares somehow that the expression
passed should not be evaluated at the caller site, but rather wrapped
in a closure and passed to the callee.
Not only is the caller site easier to write, also in the callee code
you just evaluate the parameter, you don't have to explicitly call it.
I understand that this "by-name" mechanism requires the compiler to
know the callee prototype at the caller site, and is therefore well
suited for statically linked languages like Scala but not that much
for Lua. But maybe there is an "implicit closure creation" solution
that would fit Lua.