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

Re: Inline VALOF



Hi,

David Wood wrote:

> Since we added user-defined operators, you can write:
> 
> INT INLINE FUNCTION "??" (VAL BOOL b, VAL [2]INT x) IS x[INT b]:
> 
> (overloaded for any types you like), and then
> 
>   delay := (urgent ?? [1, 2]) * weeks
> 
> The only problem I can think of is that both expressions (1 and 2 above)
> are evaluated.
> 
> (And that it's the wrong way round -- make that x[1 - (INT b)] or
> x[INT (NOT b)].)

Nice!  Yes, if we ramp up occam's expression structures, we ought to go
for lazy evaluation.  Once upon a time, I wanted to write:

  [<exp-0>, <exp-1>, <exp-2>, <exp-3>][i]

where the expressions were computationally heavy and only one, of course,
was needed.

Peter.