fix more bugs, thanks Kyle
authorJim <jim.pryor@nyu.edu>
Sun, 1 Feb 2015 21:19:55 +0000 (16:19 -0500)
committerJim <jim.pryor@nyu.edu>
Sun, 1 Feb 2015 21:19:55 +0000 (16:19 -0500)
topics/week1.mdwn

index 5ab30bc..446d7a7 100644 (file)
@@ -537,7 +537,7 @@ As we said, this is deep and exciting, and it will make your head spin before we
 Finally, we're in a position to revisit the two definitions of `length` that Jim presented in class. Here is the first:
 
 `letrec`  
-&nbsp;&nbsp;`length match` &lambda; `xs. case xs of [] then 0; _:ys then 1 + length ys end`  
+&nbsp;&nbsp;`length match` &lambda; `xs. case xs of [] then 0; _ & ys then 1 + length ys end`  
 `in length`
 
 This function accept a sequence `xs`, and if it's empty returns `0`, else it says that its length is `1` plus whatever is the length of its remainder when you take away the first element. In programming circles, this remainder is commonly called the sequence's "tail" (and the first element is its "head").
@@ -547,7 +547,7 @@ Thus if we evaluated `length [10, 20, 30]`, that would give the same result as `
 Here's another way to define the `length` function:
 
 `letrec`  
-&nbsp;&nbsp;`aux match` &lambda; `(n, xs). case xs of [] then n; _:ys then aux (n + 1, ys) end`  
+&nbsp;&nbsp;`aux match` &lambda; `(n, xs). case xs of [] then n; _ & ys then aux (n + 1, ys) end`  
 `in` &lambda; `xs. aux (0, xs)`
 
 This may be a bit confusing. What we have here is a helper function `aux` (for "auxiliary") that accepts *two* arguments, the first being a counter of how long we've counted in the sequence so far, and the second argument being how much more of the sequence we have to inspect. If the sequence we have to inspect is empty, then we're finished and we can just return our counter. (Note that we don't return `0`.) If not, then we add `1` to the counter, and proceed to inspect the tail of the sequence, ignoring the sequence's first element. After the `in`, we can't just return the `aux` function, because it expects two arguments, whereas `length` should just be a function of a single argument, the sequence whose length we're inquiring about. What we do instead is return a &lambda;-generated function, that expects a single sequence argument `xs`, and then returns the result of calling `aux` with that sequence together with an initial counter of `0`.