tweaked week3
authorJim Pryor <profjim@jimpryor.net>
Sat, 18 Sep 2010 21:51:27 +0000 (17:51 -0400)
committerJim Pryor <profjim@jimpryor.net>
Sat, 18 Sep 2010 21:51:27 +0000 (17:51 -0400)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
week3.mdwn

index 9e67041..a01df34 100644 (file)
@@ -36,7 +36,7 @@ What is the `let rec` in the OCaml code and the `letrec` in the Scheme code? The
 
 In Scheme:
 
 
 In Scheme:
 
-       (letrec [(get_length 
+       (letrec [(get_length 
                                (lambda (lst) (if (null? lst) 0 [+ 1 (get_length (cdr lst))] )) )]
                        (get_length (list 20 30)))
        ; this evaluates to 2
                                (lambda (lst) (if (null? lst) 0 [+ 1 (get_length (cdr lst))] )) )]
                        (get_length (list 20 30)))
        ; this evaluates to 2
@@ -50,7 +50,7 @@ If you instead use an ordinary `let` (or `let*`), here's what would happen, in O
 
 Here's Scheme:
 
 
 Here's Scheme:
 
-       (let* [(get_length 
+       (let* [(get_length 
                                (lambda (lst) (if (null? lst) 0 [+ 1 (get_length (cdr lst))] )) )]
                        (get_length (list 20 30)))
        ; fails with error "reference to undefined identifier: get_length"
                                (lambda (lst) (if (null? lst) 0 [+ 1 (get_length (cdr lst))] )) )]
                        (get_length (list 20 30)))
        ; fails with error "reference to undefined identifier: get_length"
@@ -100,10 +100,10 @@ So how could we do it? And how do OCaml and Scheme manage to do it, with their `
 
 2.     If you tried this in Scheme:
 
 
 2.     If you tried this in Scheme:
 
-               (define get_length 
+               (define get_length 
                                (lambda (lst) (if (null? lst) 0 [+ 1 (get_length (cdr lst))] )) )
 
                                (lambda (lst) (if (null? lst) 0 [+ 1 (get_length (cdr lst))] )) )
 
-               (get_length (list 20 30))
+               (get_length (list 20 30))
 
        You'd find that it works! This is because `define` in Scheme is really shorthand for `letrec`, not for plain `let` or `let*`. So we should regard this as cheating, too.
 
 
        You'd find that it works! This is because `define` in Scheme is really shorthand for `letrec`, not for plain `let` or `let*`. So we should regard this as cheating, too.