37 2. `cdr` is function that gets the tail of a Scheme list. (By definition, it's the function for getting the second member of a [[dotted pair|week3_unit#imp]]. As we discussed in notes for last week, it just turns out to return the tail of a list because of the particular way Scheme implements lists.) `List.tl` is the function that gets the tail of an OCaml list.

44 Answer: These work a lot like `let` expressions, except that they let you use the variable `length` *inside* the body of the function being bound to it --- with the understanding that it will there be bound to *the same function* that you're *then* in the process of binding `length` to. So our recursively-defined function works the way we'd expect it to. Here is OCaml:

119 1. OCaml and Scheme do it using a trick. Well, not a trick. Actually an impressive, conceptually deep technique, which we haven't yet developed. Since we want to build up all the techniques we're using by hand, then, we shouldn't permit ourselves to rely on `let rec` or `letrec` until we thoroughly understand what's going on under the hood.

131 3. In fact, it *is* possible to define the `length` function in the Lambda Calculus despite these obstacles, without yet knowing how to implement `letrec` in general. We've already seen how to do it, using our right-fold (or left-fold) encoding for lists, and exploiting their internal structure. Those encodings take a function and a seed value and returns the result of folding that function over the list, with that seed value. So we could use this as a definition of `length`:

135 What's happening here? We start with the value `0`, then we apply the function `\x sofar. succ sofar` to the two arguments <code>x<sub>n</sub></code> and `0`, where <code>x<sub>n</sub></code> is the last element of the list. This gives us `succ 0`, or `1`. That's the value we've accumulated "so far." Then we go apply the function `\x sofar. succ sofar` to the two arguments <code>x<sub>n-1</sub></code> and the value `1` that we've accumulated "so far." This gives us `2`. We continue until we get to the start of the list. The value we've then built up "so far" will be the length of the list.

151 As we've seen, it does take some ingenuity to define functions like `tail` or `pred` for our right-fold encoding of lists. However it can be done. (And it's not *that* difficult.) Given those functions, we can go on to define other functions like numeric equality, subtraction, and so on, just by exploiting the structure already present in our implementation of lists and numbers.

153 With sufficient ingenuity, a great many functions can be defined in the same way. For example, the factorial function is straightforward. The function which returns the *n*th term in the Fibonacci series is a bit more difficult, but also achievable.

179 But functions like the Ackermann function require us to develop a more general technique for doing recursion --- and having developed it, it will often be easier to use it even in the cases where, in principle, we didn't have to.

210 This is a bit different than the general mathematical definition, in that here we're saying it is *terms* that are fixed points, not *values*. We like to think that some lambda terms represent values, such as our term `\f z. z` representing the numerical value zero (and also the truth-value false, and also the empty list... on the other hand, we never did explicitly agree that those three values are all the same thing, did we?). But some terms in the Lambda Calculus don't even have a normal form. We don't want to count them as *values*. Yet the way we're proposing to use the notion of a fixed point here, they too are allowed to be fixed points, and to have fixed points of their own.

212 Note that `M <~~> N` doesn't entail that `M` and `N` have a normal form (though if they do, they will have the same normal form). It just requires that there be some term that they both reduce to. It may be that *that* term itself never stops being reducible.

300 where that whole formula is convertible with the term `LENGTH` itself. In other words, the term `Φ[...LENGTH...]` contains (a term that convertible with) itself --- despite being only finitely long. (If it had to contain a term *syntactically identical to* itself, this could not be achieved.)

403 But the argument of `h` in the last line is just the same as the second line, which `<~~> Y h`. So the last line `<~~> h (Y h)`. In other words, `Y h <~~> h (Y h)`. So by definition, `Y h` is a fixed point for `h`.

505 Applying either of these to a term `h` gives a fixed point `ξ` for `h`, meaning that `h ξ` <~~> `ξ`. The combinator `Θ′` has the advantage that `h (Θ′ h)` really *reduces to* `Θ′ h`. Whereas `h (Y′ h)` is only *convertible with* `Y′ h`; that is, there's a common formula they both reduce to. For most purposes, though, either will do.

514 We stated the more complex formulas for the following reason: in a language whose evaluation order is *call-by-value*, the evaluation of `Θ (\body. BODY)` and `Y (\body. BODY)` won't terminate. But evaluation of the eta-unreduced primed versions may.

542 to *the tail* of the list we were evaluating its application to at the previous stage. Assuming our lists are finite (and the encodings we've been using so far don't permit otherwise), at some point one will get a list whose tail is empty, and then the evaluation of that formula to that tail will return `0`. So the recursion eventually bottoms out in a base value.

549 There's a tendency for people to say "Y-combinator" to refer to fixed-point combinators generally. We'll probably fall into that usage ourselves. Speaking correctly, though, the Y-combinator is only one of many fixed-point combinators.