week1: rosetta tweaks
[lambda.git] / damn.mdwn
index 0b1f1f3..9896c58 100644 (file)
--- a/damn.mdwn
+++ b/damn.mdwn
@@ -1,13 +1,24 @@
+1.     Sentences have truth conditions.
+
+2.     If "John read the book" is true, then it follows that:
+       John read something,  
+       Someone read the book,  
+       John did something to the book,  
+       etc.
+
+3. If "John read the damn book",
+   all the same entailments follow.
+   To a first approximation, "damn" does not affect at-issue truth
+   conditions.  
+
+4. "Damn" does contribute information about the attitude of the speaker
+   towards some aspect of the situation described by the sentence.
+
+
 Expressives such as "damn" have side effects that don't affect the
 at-issue value of the sentence in which they occur.  What this claim
 says is unpacked at some length here: <http://tinyurl.com/cbarker/salt/interaction/salt.pdf>.
 
-<!--
-Chris also emailed me this paper, may this be publicly posted?
-<http://tinyurl.com/cbarker/salt/interaction/salt.pdf>
--->
-
-
 In brief, "The man read the damn book" means the same thing as "The
 man read the book" as far as what must be the case in the world for
 the sentence to be true.  However, the sentence with the "damn" in it
@@ -24,19 +35,9 @@ Furthermore, we don't want to change the meaning of "the", "man",
 shouldn't be burdened with helping compute affective content.
 
 
-Some nice things: we can remove one or both of the damns, or add more,
-and everything works.  As desired, the rest of the words don't need to
-know anything about side effects.
-
-Some of the complexities:
-
-Because the compositional semantics doesn't know about words that
-denote functions, "damn" contributes a trivial adjectival meaning
-(here, the identity function 'id) to the composition.
-
-
 
-What we did in Monday's seminar:
+What we did in Monday's seminar
+===============================
 
 We start with a simulation of semantic composition:
 
@@ -45,20 +46,36 @@ We start with a simulation of semantic composition:
                                (cons 'the
                                          'book)))
 
-; evaluates to ((the . man) . (read . (the . book)))
+That evaluates to nested structure of pairs, that Scheme displays as:
+
+       '((the . man) . (read . (the . book)))
+
+If you try it yourself, you may see instead:
+
+       '((the . man) read the . book)
+
+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 the pair that way yourself:
-if you tried to, Scheme would think you're trying to apply the function M to some arguments, which you're not, and also
+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
 Scheme would be confused by what argument the `.` is supposed to be. So, you say:
+
        (cons M N)
+
 and that evaluates to an ordered pair, and Scheme displays that ordered pair as
-       (M . N)
+
+       '(M . N)
+
+You *can* write `'(M . N)` (with the prefixed single quote), and Scheme will understand you then. However, we're going to be using that same single quote prefix to do something else in a moment, and I don't want now to explain how these uses are related. So we'll write out `(cons M N)` longhand, and we'll leave the `'(M . N)` notation to Scheme for displaying the pair we built.
+
 There is an underlying reason why parentheses are used both when displaying the ordered pair, and also to mean "apply this function to these arguments." However, at this point, you may well see this as a confusing overloading of parentheses to fill different syntactic roles.
 
-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 dummy value THE to stand for the meaning of an object-language determiner, and some dummy value MAN to stand for the meaning of an object-language noun phrase. The notation `'the` is Scheme's way of representing a dummy, atomic value. Note there is no closing single quote, only a prefixed one. Scheme calls these dummy 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 itself has no parts.) If you think this is all somewhat confusing, you're right. It gets easier with practice.
+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. 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,43 +90,44 @@ The program we submitted to Scheme:
 
 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:
-;
-
-             /----------------\
-            /                  \
-           /                    \
-          /                      \
-         /                        \                                  
-        / \                      / \
-       /   \                    /   \
-      /     \                  /     \
-     /       \                /       \
-meaning of   meaning of   meaning of   \
-  "the"        "man"       "read"      / \
-                                      /   \
-                                     /     \
-                                    /       \
-                                                               meaning of  meaning of
-                                                                 "the"      "book"
+       '((the . man) . (read . (the . book)))
+
+---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:
+
+                                /----------------\
+                               /                  \
+                          /                    \
+                         /                      \
+                        /                        \                                  
+                       / \                      / \
+                  /   \                    /   \
+                 /     \                  /     \
+                /       \                /       \
+       meaning of   meaning of   meaning of   \
+         "the"        "man"       "read"      / \
+                                                                                 /   \
+                                                                                /     \
+                                                                               /       \
+                                                                       meaning of  meaning of
+                                                                         "the"      "book"
 
 Okay, let's get back to "damn."
 
-We start by defining `damn` as a "thunk" that when applied to 0 arguments returns a trivial adjectival meaning, which we'll designate with the dummy symbol `'id`.
+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 1 value, and also functions that take 2 values, and also functions that take 0 values. The last ones are called "thunks." The thunk is not identical to the value it returns. For instance:
+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 call it a "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.
+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.
 
-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`:
 
@@ -125,10 +143,15 @@ Now we can say:
 
 and we get back:
 
-       ((the . man) . (read . (the . (id . book))))
+       '((the . man) . (read . (the . (id . book))))
 
+---or an equivalent shorthand. (I'm now going to stop saying this.)
 
-Now we want to get some expressive meaning into damn. So we might try:
+
+How to get some affective meaning into damn?
+--------------------------------------------
+
+We might try:
 
 
        (define damn (lambda () 'bad))
@@ -143,32 +166,40 @@ 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 "bad" to be contributed as a linguistic move on the side. We might try:
+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:
 
        (define damn (lambda () (cons 'side-effect 'bad)))
 
 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. (I'll use `<>` to indicate a "hole" in a larger expression.)
 
-And the context `(the . ( ... . book))` presumably doesn't know how to interact with side-effects. 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 papers linked above. For a simple in-class demonstration, we tried to do this.
+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 ...))` is Scheme's way of writing: bind the continuation of this very complex expression to k and evaluate the `...`.
+       (call/cc (lambda (k) ...))
 
-So now we define `damn` like this:
+is Scheme's way of saying:
+       
+>      bind the continuation of this complex expression to `k` and evaluate the `...`
 
 
+So now we define `damn` like this:
+
        (define damn (lambda () (call/cc (lambda (k) (print "bad") (k 'id)))))
 
-Now when we do:
+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:
 
        (cons (cons 'the 'man) 
                  (cons 'read
@@ -176,140 +207,146 @@ Now when we do:
                                          (cons (damn) 
                                                'book))))
 
-we get something like this:
+We get something like this:
 
-       <bold>"bad"</bad> ((the . man) . (read . (the . (id . book))))
+<blockquote>
+<strong>"bad"</strong> '((the . man) . (read . (the . (id . book))))
+</blockquote>
 
-Yay! The expressive 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.** 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:
+
+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:
 
        (define three-thunk (lambda () (print "hi") 3))
 
 and then ask for the evaluation of:
 
-       (+ 2 (three-thunk))
+       (+ (+ 2 (three-thunk)) 1)
 
 you'll see something like:
 
-       <bold>"hi"</bad> 5
+<blockquote>
+<strong>"hi"</strong> 6
+</blockquote>
+
+In other words, the printing of "hi" already happens on the side, outside of the main evaluation. Continuations don't need to be explicitly invoked.
 
-So the demonstration we tried in class was pedagogically flawed. It didn't properly display how continuations represent a minimally effective apparatus for representing expressive content. 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 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.
 
 
+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:
+
+       (cons (cons 'the 'man) 
+                 (cons 'read
+                               (cons 'the
+                                         (cons (damn) 
+                                               'book))))
 
+where `(damn)` doesn't have widest scope. And we don't want to have to recruit all the other semantic material into accepting and passing along a possible affective argument.
 
+How to do this?
 
------ End forwarded message -----
+It's not immediately clear how to do it with "undelimited" continuations, of the sort captured by `call/cc`. This is the natural first thing to try:
 
 
+       (define damn (lambda () (call/cc (lambda (k) (cons (cons 'side-effect 'bad) (k 'id))))))
 
-#lang racket
-;(define damn (lambda () 'id))
-(define damn (lambda () (call/cc (lambda (k) 
-                                  ; (k 'id)
-                                   (print "Something's bad")
-                                   (k 'id)
-                                   ))))
 
-(list (list 'the (list (damn) 'man))
-      (list 'read 
-            (list 'the (list (damn) 'book))))
+The idea here is we capture the continuation that `(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 application of `(cons (cons 'side-effect 'bad) <>)` to anything.
 
 
+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.
 
-#lang racket
-(require racket/control)
+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:
 
-(define damn0 (lambda ()
-                               'id))
+       (call/cc (lambda (k) ...))
 
-(define damn1 (lambda ()
-                               (cons '("side effect" bad)
-                                         'id)))
+we instead write:
 
-(define damn2 (lambda () (shift k
-                                                               (cons '("side effect" bad) 
-                                                                         (list (k 'id))))))
+       (shift k ...)
 
-(define damn3 (lambda () (shift k
-                                                               (list (k 'id)
-                                                                         '("side effect" bad)))))
+but the behavior is the same. It's just that now our continuation doesn't stretch until the end of the computation, but only up to some specified limit. The limit of the continuation is specified using the syntax:
 
+       (reset ...)
 
-; Now if we use damn0, our compositional semantics will work OK but
-; we don't yet have any expressive contribution:
+This is a kind of continuation-scope-marker. There are some interesting default behaviors if you don't explicitly specify where the limits are. In fact, in the interactive interpreter we wouldn't need to ever explicitly mark the scopes. They'd by default be just where we want them to be. But we'll be fully explicit here.
 
-(list "main content" 'i (list 'like (list 'the (damn0) 'boy)))
-; '("main content" i (like (the id boy)))
+If a block `...` never invokes a shift, then `(reset ...)` will evaluate just the same as `...`. So for uniformity, we can designate our continuation-scopes even on computations that don't capture and manipulate continuations.
 
+Going back to the beginning, then. We start with:
 
-; If we use damn1, we've added in the expressive side-effect:
+       (require racket/control) ; this tells Scheme to let us use shift and reset
 
-(list "main content" 'i (list 'like (list 'the (damn1) 'boy)))
-; '("main content" i (like (the (("side effect" bad) . id) boy)))
+       (define damn (lambda () 'id))
 
-; 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
-; have something different here.
+We evaluate:
 
-; To get what we want we need to use (delimited) continuations:
-(reset (list "main content" 'i (list 'like (list 'the (damn2) 'boy))))
-; '(("side effect" bad) ("main content" i (like (the id boy))))
+       (reset (cons (cons 'the 'man) 
+                 (cons 'read
+                               (cons 'the
+                                         (cons (damn) 
+                                               'book)))))
 
-; or to get the side effect at the end:
+Remember, the reset isn't actually *doing* anything. It's not a function that's taking the other material as an argument. It's instead a scope-marker. Here it's not even needed; but we're inserting it anyway to be explicit and uniform.
 
-(reset (list "main content" 'i (list 'like (list 'the (damn3) 'boy))))
-; '(("main content" i (like (the id boy))) ("side effect" bad))
+Evaluating that gives us:
 
-; If you're working in the interactive interpreter, the outermost "reset" here
-; is already in its default position, so it doesn't need to be explicitly
-; specified:
+       '((the . man) . (read . (the . (id . book))))
 
-(list "main content" 'i (list 'like (list 'the (damn2) 'boy)))
-; '(("side effect" bad) ("main content" i (like (the id boy))))
 
-; However, if you're executing this as a file, you would need to include explicit resets.
+Now to pair that with an affective side-issue content, we'd instead define `damn` as:
 
+       (define damn (lambda () (shift k (cons (cons 'side-effect 'bad) (k 'id)))))
 
+And voil&agrave;!
 
-; 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
-; explicit continuation, but as Chris said, that's because "print" already
-; represents an implicit continuation.
+       (reset (cons (cons 'the 'man) 
+                 (cons 'read
+                               (cons 'the
+                                         (cons (damn) 
+                                                       'book)))))
 
-(define damn4 (lambda () (begin (print "bad") 'id)))
-(list "main content" 'i (list 'like (list 'the (damn4) 'boy)))
-; "bad"'("main content" i (like (the id boy)))
-;
+evaluates to:
 
+       '((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.
 
 
-#lang racket
+Ken's proposal
+--------------
 
-; thanks to Ken!
+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
-       ; operator, a unary function, and whose second component
-       ; is the meaning of "damn", a thunk.
-       (call-with-current-continuation
-        (lambda (k)
-          (cons (lambda (prop) prop)
-                (lambda () (k (cons (lambda (prop) (list 'bad prop))
-                                    (lambda () 'id)))))))))
-  (let ((assert (car pragma))
-        (damn   (cdr pragma)))
-    (assert (list 'the 'student 'read 'the (damn) 'book))))
+       (let ((pragma
+                  ; An ordered pair whose first component is the assertion
+                  ; operator, a unary function, and whose second component
+                  ; is the meaning of "damn", a thunk.
+                  (call/cc (lambda (k)
+                         (cons (lambda (p) p)
+                                       (lambda () (k (cons (lambda (p) (cons (cons 'side-effect 'bad) p))
+                                                                               (lambda () 'id)))))))))
+         (let ((assert (car pragma)) ; this binds assert to the first element of the pair pragma
+                       (damn   (cdr pragma))) ; this binds damn to the second element of the pair pragma
+               (assert (cons (cons 'the 'man) (cons 'read (cons 'the (cons (damn) 'book)))))))
 
+We won't do much to explain this. We'll just leave it for you to digest, perhaps later in the course. When you succeed in doing so, you will be as delighted by it as we are.