Merge branch 'working'
[lambda.git] / topics / week4_more_about_fixed_point_combinators.mdwn
index 763c18b..3d4f50a 100644 (file)
@@ -370,3 +370,25 @@ Success.
 
 So the function `\h. (\u. h (u u)) (\u. h (u u))` maps an arbitrary term
 `h` to a fixed point for `h`.
+
+
+## Q: How does this relate to the discussion in Chapter 9 of The Little Schemer? ##
+
+A: Pages 160-172 of *The Little Schemer* introduce you to how to implement recursion in Scheme, without relying on the native capacity to do this expressed in `letrec` or `define`. The expression:
+
+    (lambda (length)
+      (lambda (l)
+        (cond
+          ((null? l) 0)
+          (else (add1 (length (cdr l)))))))
+
+that occurs starting on p. 162 and on several pages following corresponds to `h` in [[our exposition|week4_fixed_point_combinators#little-h]]. The authors of *The Little Schemer* begin by applying that abstract to the argument `eternity`, which is a function that never returns; then they instead apply it to the argument `h eternity`, which is a function that works for lists of length zero, but otherwise never returns; then to the argument `h (h eternity)`, which works for lists of length zero or one, but otherwise never returns; and so on.
+
+They work their way towards the realization that they want an "infinite tower" of applications of `h`, except they don't really need an infinite tower, but rather just a finite tower whose height can't be bounded in advance. This is essentially the observation that they need a fixed point for `h`.
+
+The authors attempt to self-apply `h` on p. 165, just as we did. As we explained in [[our exposition|week4_fixed_point_combinators#deriving-y]], though, that doesn't quite work.
+
+On the top of p. 167, the authors have instead moved to our `H`, and attempt to self-apply that, instead. And this works.
+
+However, on p. 168, they attempt to abstract out the part that in our `H` looks like `(u u)` and in their exposition looks like `(mk-length mk-length)`. Doing that *would* work in our lambda evaluator, but you can't do it in Scheme, because Scheme has call-by-value evaluation order, which will try to fully reduce this expression before substituting it back into the term it's been abstracted out of. But it can't be fully reduced. Pages 168--170 explore this problem, and pp. 170--172 hit upon the solution of using what we called in our exposition the `Y′` fixed-point combinator, rather than the `Y` combinator that we derived. The authors of *The Little Schemer* call `Y′` the "applicative-order Y combinator".
+