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

index 58a2a03..8ee80b4 100644 (file)
@@ -356,3 +356,66 @@ combinatorial logic</td>
 <td width=30%>&nbsp;
 </table>
 
 <td width=30%>&nbsp;
 </table>
 
+Rosetta Stone
+=============
+
+Here's how it looks to say the same thing in various of these languages.
+
+1.     Binding suitable values to the variables `three` and `two`, and adding them.
+
+       In Scheme:
+
+               (let* ((three 3))
+                         (let ((two 2))
+                                  (+ three two)))
+
+       In OCaml:
+
+               let three = 3 in
+                       let two = 2 in
+                               three + two
+
+       Notice OCaml lets you write the `+` in between the `three` and `two`, as you're accustomed to. However most functions need to come leftmost, even if they're binary. And you can do this with `+` too, if you enclose it in parentheses so that the OCaml parser doesn't get confused by your syntax:
+
+               let three = 3 in
+                       let two = 2 in
+                               ( + ) three two
+
+       In the lambda calculus: here we're on our own, we don't have predefined constants like `+` and `3` and `2` to work with. We've got to build up everything from scratch. We'll be seeing how to do that over the next weeks.
+
+       But supposing you had constructed appropriate values for `+` and `3` and `2`, you'd place them in the ellided positions in:
+
+               (((\three (\two ((... three) two))) ...) ...)
+       
+       In an ordinary imperatival language like C:
+
+               int three = 3;
+               int two = 2;
+               three + two;
+
+2.     Mutation
+
+       In C this looks almost the same as what we had before:
+
+               int x = 3;
+               x = 2;
+
+       Here we first initialize `x` to hold the value 3; then we mutate `x` to hold a new value.
+
+       In (the imperatival part of) Scheme, this could be done as:
+
+               (let ((x (box 3)))
+                        (set-box! x 2))
+
+       In general, mutating operations in Scheme are named with a trailing `!`. There are other imperatival constructions, though, like `(print ...)`, that don't follow that convention.
+
+       In (the imperatival part of) OCaml, this could be done as:
+
+               let x = ref 3 in
+                       x := 2
+
+       Of course you don't need to remember any of this syntax. We're just illustrating it so that you see that in Scheme and OCaml it looks somewhat different than we had above. The difference is much more obvious than it is in C.
+
+       In the lambda calculus: sorry, you can't do mutation. At least, not natively. Later in the term we'll be learning how in fact, really, you can embed mutation inside the lambda calculus even though the lambda calculus has no primitive facilities for mutation.
+
+