week1: fix markup processing?
authorJim Pryor <profjim@jimpryor.net>
Thu, 16 Sep 2010 03:10:05 +0000 (23:10 -0400)
committerJim Pryor <profjim@jimpryor.net>
Thu, 16 Sep 2010 03:10:05 +0000 (23:10 -0400)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
test2.mdwn

index 138ee50..afe1b69 100644 (file)
@@ -533,3 +533,71 @@ Here's how it looks to say the same thing in various of these languages.
        Read this several times until you understand it.
 
 
+7.     Functions can also be bound to variables (and hence, cease being "anonymous").
+
+       In Scheme:
+
+               (let* [(bar (lambda (x) B))] M)
+
+       then wherever `bar` occurs in `M` (and isn't rebound by a more local "let" or "lambda"), it will be interpreted as the function `(lambda (x) B)`.
+
+       Similarly, in OCaml:
+
+               let bar = fun x -> B in
+                       M
+
+       This in Scheme:
+
+               (let* [(bar (lambda (x) B))] (bar A))
+
+       as we've said, means the same as:
+
+               ((lambda (bar) (bar A)) (lambda (x) B))
+
+       which, as we'll see, is equivalent to:
+
+               ((lambda (x) B) A)
+
+       and that means the same as:
+
+               (let* [(x A)] B)
+
+       in other words: evaluate `B` with `x` assigned to the value `A`.
+
+       Similarly, this in OCaml:
+
+               let bar = fun x -> B in
+                       bar A
+
+       is equivalent to:
+
+               (fun x -> B) A
+
+       and that means the same as:
+
+               let x = A in
+                       B
+
+8.     Pushing a "let"-binding from now until the end
+
+       What if you want to do something like this, in Scheme?
+
+               (let* [(x A)] ... for the rest of the file or interactive session ...)
+
+       or this, in OCaml:
+
+               let x = A in
+                       ... for the rest of the file or interactive session ...
+
+       Scheme and OCaml have syntactic shorthands for doing this. In Scheme it's written like this:
+
+               (define x A)
+               ... rest of the file or interactive session ...
+
+       In OCaml it's written like this:
+
+               let x = A;;
+               ... rest of the file or interactive session ...
+
+       It's easy to be lulled into thinking this is a kind of imperative construction. *But it's not!* It's really just a shorthand for the compound "let"-expressions we've already been looking at, taking the maximum syntactically permissible scope. (Compare the "dot" convention in the lambda calculus, discussed above.)
+