lua-users home
lua-l archive

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


In message <52FE66A0-6E4F-4286-BE9C-F8DA1D9A2BB8@dnainternet.net> you wrote:


> Exercise 1.4.  Observe that our model of evaluation allows for  
> combinations whose operators are compound expressions. Use this  
> observation to describe the behavior of the following procedure:
> 
> (define (a-plus-abs-b a b)
>    ((if (> b 0) + -) a b))
> 
> <<
> 
> ...and the point was...?
> 
Sorry - I was being too telegraphic. The point is that functions
in Lua, as in Scheme, are eager in all their arguments, whereas the
conditional expression

      c and x or y

is eager only in c but lazy in x and y. The exercise was intended
to bring home the fact that without a regime of lazy evaluation
for functions you cannot use functions to produce the same behaviour as
the conditional expression. This is a classic 'gotcha' often
trotted out in the study of functional programming.

-- 
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/