<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16788" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face="Courier New" size=2>There is an important difference between
normal order and lazy order. But let's assume you really mean lazy order. In
that case you need to use syntax `lazy', not `delay' (see srfi 45,
immediately available in PLT's scheme/base) When using delay, you may easily
create deeply nested promises. For example, when you implement promises simply
as:</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>(define-syntax delay (syntax-rules () ((_
x) (lambda () x))))</FONT></DIV>
<DIV><FONT face="Courier New" size=2>(define (force x) (x))</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>you are going to have problems. You need a
more subtle type of promises (those like srfi 45)</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>In normal order ((lambda (x) (cons x x))
(begin (write 'foo) 'foo)) writes `foo' twice, in lazy order once only. You
might check for that. If you implemented normal order rather than lazy order,
the problem does not surprise me. You may also want to look into srfi 41
(streams) which implements and shows many examples of lazy order
evaluation.</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>I have two implementations that allow
mixing lazy and eager evaluation, but I am not yet satisfied about them and
therefore do not yet want to present them to this list. If you are interested,
let me know. Last but not least, did you look in the lazy scheme of PLT? Very
instructive.</FONT></DIV>
<DIV><FONT face="Courier New" size=2>Jos</FONT></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=jcoglan@googlemail.com href="mailto:jcoglan@googlemail.com">James
Coglan</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=plt-scheme@list.cs.brown.edu
href="mailto:plt-scheme@list.cs.brown.edu">PLT Scheme ML</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Saturday, January 17, 2009 3:42
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [plt-scheme] Lazy evaluation and
tail calls</DIV>
<DIV><BR></DIV>Hi there,<BR><BR>My apologies if this is the wrong place to be
asking this, but I'm new to Scheme and am not sure where I can get this
question answered. If you know a better place to ask this, please point me in
the right direction.<BR><BR>Basically, I'm learning Scheme by implementing it
in Ruby while reading SICP. I've added tail calls and also an optional lazy
(normal-order) evaluation mode, but I can't get the two to play together. I
have a factorial function that runs iteratively in eager mode, but it blows up
the stack in lazy mode.<BR><BR>I was wondering whether it's possible to have
tail call optimisation when using normal order. I don't want to bang my head
against the wall trying to make it happen if it can't be done.<BR
clear=all><BR>-- <BR>James Coglan<BR>
<P>
<HR>
<P></P>_________________________________________________<BR> For
list-related administrative tasks:<BR>
http://list.cs.brown.edu/mailman/listinfo/plt-scheme<BR></BLOCKQUOTE></BODY></HTML>