% $Id: FibLazy.oz,v 1.1 2007/10/14 17:56:08 leavens Exp leavens $ declare %%% The following doesn't work well, %%% as it doesn't make sure that the by-need triggers are unique. fun lazy {BadFib N} if N =< 1 then 1 else {Fib N-2} + {Fib N-1} end end %%% The following, on the other hand, is fine %%% since it keeps a unique list of by-need triggers local FibList MkFibList in fun lazy {MkFibList FibNm1 FibNm2} local FibN = FibNm1+FibNm2 in FibN|{MkFibList FibN FibNm1} end end FibList = 1|1|{MkFibList 1 1} fun {Fib N} {Nth FibList N+1} end end