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

index afe1b69..dcc8a1a 100644 (file)
@@ -601,3 +601,80 @@ Here's how it looks to say the same thing in various of these languages.
 
        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.)
 
+
+9.     Some shorthand
+
+       OCaml permits you to abbreviate:
+
+               let bar = fun x -> B in
+                       M
+
+       as:
+
+               let bar x = B in
+                       M
+
+       It also permits you to abbreviate:
+
+               let bar = fun x -> B;;
+
+       as:
+
+               let bar x = B;;
+
+       Similarly, Scheme permits you to abbreviate:
+
+               (define bar (lambda (x) B))
+
+       as:
+
+               (define (bar x) B)
+
+       and this is the form you'll most often see Scheme definitions written in.
+
+       However, conceptually you should think backwards through the abbreviations and equivalences we've just presented.
+
+               (define (bar x) B)
+
+       just means:
+
+               (define bar (lambda (x) B))
+
+       which just means:
+
+               (let* [(bar (lambda (x) B))] ... rest of the file or interactive session ...)
+
+       which just means:
+
+               (lambda (bar) ... rest of the file or interactive session ...) (lambda (x) B)
+
+       or in other words, interpret the rest of the file or interactive session with `bar` assigned the function `(lambda (x) B)`.
+
+
+10.    Shadowing
+
+       You can override a binding with a more inner binding to the same variable. For instance the following expression in OCaml:
+
+               let x = 3 in
+                       let x = 2 in
+                               x
+
+       will evaluate to 2, not to 3. It's easy to be lulled into thinking this is the same as what happens when we say in C:
+
+               int x = 3;
+               x = 2;
+       
+       <em>but it's not the same!</em> In the latter case we have mutation, in the former case we don't. You will learn to recognize the difference as we proceed.
+
+       The OCaml expression just means:
+
+               (fun x -> ((fun x -> x) 2) 3)
+
+       and there's no more mutation going on there than there is in:
+
+       <pre>
+       <code>&forall;x. (F x or &forall;x (not (F x)))</code>
+       </pre>
+
+       When a previously-bound variable is rebound in the way we see here, that's called **shadowing**: the outer binding is shadowed during the scope of the inner binding.
+