On Thu, Jan 24, 2008 at 12:53:59PM -0800, Brad Beyenhof wrote:

Not quite.
[snip]
You can think of normal order as only using the arguments when they are
needed.

Maybe the example in the text (at the end of 1.1.5) is misleading,
then. That seems to imply that both "square" functions are expanded at
the same time. Or is that example too simplistic to demonstrate the
aspect of the evaluation that we're discussing?

The substitution model is applicative order, not normal order.  It becomes
obvious when you try substituting '(p)' in the exercise.  You never finish
since you keep getting back what you started with.  In fact, this is a good
way to explain the difference between tail recursion and non.

  (define (p x) (p (+ x 1)))

  (define (q x) (+ (q x) 1))

Some substituion on (p 1)

  (p 1)
  (p (+ 1 1)) => (p 2)
  (p (+ 2 1)) => (p 3)
  ...

And on (q 1)
  (q 1)
  (+ (q 1) 1)
  (+ (+ (q 1)))
  (+ (+ (+ (q 1))) 1)

Strictly, the would both get bigger, but the compiler is going to be smart
enough to do the addition as soon as it is able to.  The 'q' expression
can't be simplified, and can only get bigger over time.

But, yeah, the substitution model of execution is not an exact match to
evaluation models really used.  They'll get to it.

David

--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to