damn tweaks11
[lambda.git] / damn.mdwn
index 32a0a3b..33912ff 100644 (file)
--- a/damn.mdwn
+++ b/damn.mdwn
@@ -19,7 +19,8 @@ shouldn't be burdened with helping compute affective content.
 
 
 
-What we did in Monday's seminar:
+What we did in Monday's seminar
+===============================
 
 We start with a simulation of semantic composition:
 
@@ -39,6 +40,7 @@ If you try it yourself, you may see instead:
 This is shorthand for the same thing. Just trust me on that.
 
 What's going on here?
+---------------------
 
 `(cons M N)` is a request to build an ordered pair out of the values M and N.
 Scheme displays that pair as `'(M . N)` You can't write `(M . N)` yourself and expect Scheme to understand that you're talking about this pair. If you tried, to, Scheme would think you're trying to apply the function M to some arguments, which you're not, and also
@@ -56,7 +58,7 @@ There is an underlying reason why parentheses are used both when displaying the
 
 Now what about the elements of our ordered pairs. Why do we say `(cons 'the 'man)`. Why are those single quotes there? Well, if you just said `(cons the man)`, Scheme would understand `the` and `man` to be variables, and it would complain that you hadn't bound these variables to any values. We don't want to build an ordered pair out of the values possessed by variables `the` and `man`. Instead, we want to just make up some primitive value THE to stand for the meaning of an object-language determiner, and some primitive value MAN to stand for the meaning of an object-language noun phrase. The notation `'the` is Scheme's way of designating a primitive atomic value. Note there is no closing single quote, only a prefixed one. Scheme calls these primitive atomic values "symbols." That term is a bit misleading, because the symbol `'the` is not the same as the variable `the`. Neither is it the same as what's called the string `"the"`. The latter is a structured value, composed out of three character values. The symbol `'the`, on the other hand, is an atomic value. It has no parts. (The notation the programmer uses to designate this atomic value has four characters, but the value designated itself has no parts.) If you think this is all somewhat confusing, you're right. It gets easier with practice.
 
-`'the` can also be written `(quote the)`. This is even more confusing, because here the `the` is not interpreted as a variable. (Try `(let* ((the 3)) (quote the))`.) If you come across this, just read `(quote the)` as a verbose (and perhaps misleading) way of writing `'the`, not as the application of any function to any value.
+`'the` can also be written `(quote the)`. This is even more confusing, because here the `the` is not interpreted as a variable. (Try `(let* ((the 3)) (quote the))`.) If you come across `(quote the)`, just read it as a verbose (and perhaps misleading) way of writing `'the`, not as the application of any function to any value.
 
 Okay, so what we've done is just create a bunch of new atomic values `'the`, `'man`, and so on. Scheme doesn't know how to do much with these. It knows for instance that `'the` is the same value as `'the` and a different value than `'man`. But it doesn't know much more than that. That's all we need or want here.
 
@@ -73,7 +75,9 @@ evaluates to the nested structure of pairs that Scheme displays as:
 
        '((the . man) . (read . (the . book)))
 
-and that we can think of as the tree:
+---or as an equivalent shorthand. And although there aren't `'`s prefixed to each of the elements of this nested structure, those elements are still the `'the`, `'man` and so on primitive atomic values that we specified. Not the values (if any) possessed by some variables `the`, `man`, and so on.
+
+We can think of this nested structure of pairs as the tree:
 
                                 /----------------\
                                /                  \
@@ -97,17 +101,16 @@ Okay, let's get back to "damn."
 We start by defining `damn` as a "thunk" that when applied to zero arguments returns a trivial adjectival meaning, which we'll designate with the primitive symbol `'id`.
 
 What's a "thunk"?
+-----------------
 
 Remember, in Scheme you can have functions that take one value, and also functions that take two values, and also functions that take zero values. The last ones are called "thunks." The thunk is not identical to the value it returns. For instance:
 
        (lambda () 3)
 
-is a thunk that returns the integer 3. If we bind the variable `t` to that thunk, then `t` is a function (Scheme will display it as`#<procedure>`)
+is a thunk that returns the integer 3. If we bind the variable `t` to that thunk, then `t` is a function (Scheme will display it as `#<procedure>`)
 not an integer. Whereas `(t)` is an integer not a function.
 
-There's no reason yet on hand for us to make `damn` be a thunk. For present purposes, we could also just define `damn` to be the symbol `'id`. But what we're going to go on to do does require us to make `damn` be a thunk. The reason for that is to postpone the evaluation of some expressions until the continuations we want to operate on are in place.
-
-So for uniformity we're going to make `damn` be a thunk right from the beginning.
+There's no reason yet on hand for us to make `damn` be a thunk. For present purposes, we could also just define `damn` to be the symbol `'id`. But what we're going to go on to do does require us to make `damn` be a thunk. The reason for that is to postpone the evaluation of some expressions until the continuations we want to operate on are in place. So for uniformity we're going to make `damn` be a thunk right from the beginning.
 
 As we said, `damn` starts as a thunk that returns a trivial adjectival meaning `'id`:
 
@@ -123,15 +126,15 @@ Now we can say:
 
 and we get back:
 
-       ((the . man) . (read . (the . (id . book))))
-
-If you try this yourself, you may see instead:
+       '((the . man) . (read . (the . (id . book))))
 
-       '((the . man) read the id . book)
+---or an equivalent shorthand. (I'm now going to stop saying this.)
 
 
+How to get some affective meaning into damn?
+--------------------------------------------
 
-Now we want to get some affective meaning into damn. So we might try:
+We might try:
 
 
        (define damn (lambda () 'bad))
@@ -146,7 +149,7 @@ But then:
 
 gives us:
 
-       ((the . man) . (read . (the . (bad . book))))
+       '((the . man) . (read . (the . (bad . book))))
 
 Which is not quite what we're looking for. We don't want to contribute the normal adjectival meaning of "bad" to the proposition asserted. Instead we want badness to be a side-issue linguistic contribution. We might try:
 
@@ -154,16 +157,19 @@ Which is not quite what we're looking for. We don't want to contribute the norma
 
 But then we'd get:
 
-       ((the . man) . (read . (the . ((side-effect . bad) . book))))
+       '((the . man) . (read . (the . ((side-effect . bad) . book))))
 
-and we said at the outset that the context `(the . ( ... . book))` shouldn't need to know how to interact with affective meanings. That's precisely the problem we're trying to solve.
+and we said at the outset that the context `(the . (<> . book))` shouldn't need to know how to interact with affective meanings. That's precisely the problem we're trying to solve.
 
 
+Let's use continuations
+-----------------------
+
 A promising way to handle this is with **continuations**, which you will get much more familiar with as this seminar progresses. Don't worry about not understanding what's going on quite yet. This is just an advertisement that's supposed to provoke your imagination.
 
-Chris and others have applied the apparatus of continuations to the analysis of expressives in the paper cited at the top. For a simple in-class demonstration, we tried to do the following.
+Chris and others have applied the apparatus of continuations to the analysis of expressives in the paper cited at the top. For a simple in-class demonstration, here's what we tried to do.
 
-       (call/cc (lambda k ...))
+       (call/cc (lambda (k) ...))
 
 is Scheme's way of saying:
        
@@ -174,7 +180,7 @@ So now we define `damn` like this:
 
        (define damn (lambda () (call/cc (lambda (k) (print "bad") (k 'id)))))
 
-In other words, `damn` is a thunk. When that thunk is evaluated (`(damn)`), we capture the pending future of the computation and bind that to `k`. Then we print "bad" and supply the argument `'id` to `k`. This last step means we go on evaluating the pending future contribution as if `(damn)` had simply returned `'id`.
+In other words, `damn` is a thunk. When that thunk is applied---we evaluate `(damn)`---we capture the pending future of that application and bind that to `k`. Then we print "bad" and supply the argument `'id` to `k`. This last step means we go on evaluating the pending future as if `(damn)` had simply returned `'id`.
 
 What happens then when we evaluate:
 
@@ -187,12 +193,16 @@ What happens then when we evaluate:
 We get something like this:
 
 <blockquote>
-<bold>"bad"</bad> ((the . man) . (read . (the . (id . book))))
+<strong>"bad"</strong> '((the . man) . (read . (the . (id . book))))
 </blockquote>
 
-Yay! The affective meaning has jumped out of the compositional evaluation of the main sentence, and the context `(the . (... . book))` only has to deal with the trivial adjectival meaning `'id`.
+Yay! The affective meaning has jumped out of the compositional evaluation of the main sentence, and the context `(the . (<> . book))` only has to deal with the trivial adjectival meaning `'id`.
+
+
+But
+---
 
-**But.** As came out in discussion, the `print` we're using here already constitutes a kind of side-effect mechanism of its own. If you say:
+As came out in discussion, the `print` we're using here already constitutes a kind of side-effect mechanism of its own. If you say:
 
        (define three-thunk (lambda () (print "hi") 3))
 
@@ -203,16 +213,20 @@ and then ask for the evaluation of:
 you'll see something like:
 
 <blockquote>
-<bold>"hi"</bad> 5
+<strong>"hi"</strong> 5
 </blockquote>
 
 So the demonstration we tried in class was pedagogically flawed. It didn't properly display how continuations are a minimally effective apparatus for representing affective meaning. In fact, continuations were still doing the work, but it wasn't the explicit continuations we were writing out for you. It was instead continuations implicit in the `print` operation.
 
 So a better demonstration would do without any device like `print` that already incorporates continuations implicitly. Any continuation-manipulation should be fully explicit.
 
-Instead of representing the side-issue affective contribution by printing "bad", let's instead try to build a pair of side-effect contributions and main-issue assertion. Then what we want would be something like:
 
-       ((side-effect . bad) . ((the . man) . (read . (the . (id . book)))))
+Can we do better?
+-----------------
+
+Instead of representing the side-issue affective contribution by printing "bad", let's instead try to build a pair of side-effect contributions and at-issue assertion. Then what we want would be something like:
+
+       '((side-effect . bad) . ((the . man) . (read . (the . (id . book)))))
 
 Only we want to get this from the evaluation of:
 
@@ -232,15 +246,19 @@ It's not immediately clear how to do it with "undelimited" continuations, of the
        (define damn (lambda () (call/cc (lambda (k) (cons (cons 'side-effect 'bad) (k 'id))))))
 
 
-The idea here is we capture the continuation that the thunk `(damn)` has when it gets evaluated. This continuation is bound to the variable `k`. We supply `'id` as an argument to that continuation. When the main-issues tree is all built, then we return a pair `((side-effect bad) MAIN-ISSUE-TREE)`.
+The idea here is we capture the continuation that the thunk `(damn)` has when it gets evaluated. This continuation is bound to the variable `k`. We supply `'id` as an argument to that continuation. When the main, at-issue tree is all built, then we return a pair `((side-effect bad) AT-ISSUE-TREE)`.
+
+However, this doesn't work. The reason is that an undelimited continuation represents the future of the evaluation of `(damn)` *until the end of the computation*. So when `'id` is supplied to `k`, we go back to building the at-issue tree until we're finished *and that's the end of the computation*. We never get to go back and evaluate the context `(cons (cons 'side-effect 'bad) <>)`.
 
-However, this doesn't work. The reason is that an undelimited continuation represents the future of the evaluation of `(damn)` *until the end of the computation*. So when `'id` is supplied to `k`, we go back to building the main-issue tree until we're finished *and that's the end of the computation*. We never get to go back and evaluate the context `(cons (cons 'side-effect 'bad) ...)`.
+
+With undelimited continuations
+------------------------------
 
 The straightforward way to fix this is to use, not undelimited continuations, but instead a more powerful apparatus called "delimited continuations." These too will be explained in due course, don't expect to understand all this now.
 
 A delimited continuation is captured not by using `call/cc`, but instead by using a variety of other operators. We'll use the operator `shift`. This substitutes for `call/cc`. The syntax in Scheme is slightly different. Whereas we wrote:
 
-       (call/cc (lambda k ...))
+       (call/cc (lambda (k) ...))
 
 we instead write:
 
@@ -270,7 +288,7 @@ Remember, the reset isn't actually *doing* anything. It's not a function that's
 
 Evaluating that gives us:
 
-       ((the . man) . (read . (the . (id . book))))
+       '((the . man) . (read . (the . (id . book))))
 
 
 Now to pair that with an affective side-issue content, we'd instead define `damn` as:
@@ -288,12 +306,15 @@ And voila:
 
 evaluates to:
 
-       ((side-effect bad) ((the . man) . (read . (the . (id . book)))))
+       '((side-effect bad) ((the . man) . (read . (the . (id . book)))))
 
 So that's the straightforward way of repairing the strategy we used in class, without using `print`. We also have to switch to using delimited continuations.
 
 
-Ken Shan, however, pointed out a lovely way to get to the same end-point still using only undelimited continuations (`call/cc`).
+Ken's proposal
+--------------
+
+Ken Shan pointed out a lovely way to get to the same end-point still using only undelimited continuations (`call/cc`).
 
 (let ((pragma
        ; An ordered pair whose first component is the assertion
@@ -354,12 +375,12 @@ We won't do much to explain this. We'll just leave it for you to chew on.
        ; '("main content" i (like (the id boy)))
 
 
-; If we use damn1, we've added in the affective side-effect:
+; If we use damn1, we've added in the affective side effect:
 
        (list "main content" 'i (list 'like (list 'the (damn1) 'boy)))
        ; '("main content" i (like (the (("side effect" bad) . id) boy)))
 
-; However, the context (list 'the ... 'boy) is now being asked to operate
+; However, the context (list 'the <> 'boy) is now being asked to operate
 ; on an element (("side effect" bad) . id), and it may complain it doesn't
 ; know what that is. It knows how to use 'id to get (list 'the 'id 'boy),
 ; and how to use 'bad to get (list 'the 'bad 'boy), but we're supposed to
@@ -386,7 +407,7 @@ We won't do much to explain this. We'll just leave it for you to chew on.
 
 
 ; Instead of using reset/shift you could use an element like "print" in
-; building the side-effect, as we did in class. Here you wouldn't require an
+; building the side effect, as we did in class. Here you wouldn't require an
 ; explicit continuation, but as Chris said, that's because "print" already
 ; represents an implicit continuation.