<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><BR><DIV><DIV>25 maj 2005 kl. 15.50 skrev Vlad Dumitrescu:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><DIV><FONT face="Arial" size="2"><SPAN class="Apple-style-span" style="font-family: Arial; font-size: 10px; ">Hi all,</SPAN></FONT></DIV><DIV><FONT face="Arial" size="2"></FONT> </DIV><DIV><FONT face="Arial" size="2"><SPAN class="Apple-style-span" style="font-family: Arial; font-size: 10px; ">I just hit a problem where I clearly see how simple it would be with lazy evaluation. But since we don't have that, I wonder if anyone could point me to some non-lazy algorithms.</SPAN></FONT></DIV><DIV><FONT face="Arial" size="2"></FONT> </DIV></SPAN></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>By working a bit, lazy evaluation can be done... (WARNING do not use in real apps ;-)</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>For example using the macros:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>-define(delay(X), fun() -> (X) end).</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>-define(force(X), force((X))).</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>force(F) when function(F) -> F();</DIV><DIV>force(V) -> V.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>You can define a lazy algorithms (can of course only be used in this context)</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>zeros() -></DIV><DIV>    [0 | ?delay(zeros())].</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>ones() -></DIV><DIV>    [1 | ?delay(ones())].</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>twos() -></DIV><DIV>    [2 | ?delay(ones())].</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>seq(Start) -></DIV><DIV>    [Start | ?delay(seq(Start+1))].</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>sieve1(L, P) -></DIV><DIV>    [N | T1] = ?force(L),</DIV><DIV>    case N rem P of</DIV><DIV>        0 -> sieve1(T1,P);</DIV><DIV>        _ -> sieve([N | ?delay(sieve1(T1,P))])</DIV><DIV>    end.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>sieve(L) -></DIV><DIV>    [P | X] = ?force(L),</DIV><DIV>    [P | ?delay(sieve1(X, P))].</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>primes() -></DIV><DIV>    sieve(seq(2)).</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Regards</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>/Tony</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV></DIV><BR></BODY></HTML>