2 (require racket/control)
4 (define damn0 (lambda ()
7 (define damn1 (lambda ()
8 (cons '("side effect" bad)
11 (define damn2 (lambda () (shift k
12 (cons '("side effect" bad)
15 (define damn3 (lambda () (shift k
17 '("side effect" bad)))))
20 ; Now if we use damn0, our compositional semantics will work OK but
21 ; we don't yet have any expressive contribution:
23 (list "main content" 'i (list 'like (list 'the (damn0) 'boy)))
24 ; '("main content" i (like (the id boy)))
27 ; If we use damn1, we've added in the expressive side-effect:
29 (list "main content" 'i (list 'like (list 'the (damn1) 'boy)))
30 ; '("main content" i (like (the (("side effect" bad) . id) boy)))
32 ; However, the context (list 'the ... 'boy) is now being asked to operate
33 ; on an element (("side effect" bad) . id), and it may complain it doesn't
34 ; know what that is. It knows how to use 'id to get (list 'the 'id 'boy),
35 ; and how to use 'bad to get (list 'the 'bad 'boy), but we're supposed to
36 ; have something different here.
38 ; To get what we want we need to use (delimited) continuations:
39 (reset (list "main content" 'i (list 'like (list 'the (damn2) 'boy))))
40 ; '(("side effect" bad) ("main content" i (like (the id boy))))
42 ; or to get the side effect at the end:
44 (reset (list "main content" 'i (list 'like (list 'the (damn3) 'boy))))
45 ; '(("main content" i (like (the id boy))) ("side effect" bad))
47 ; If you're working in the interactive interpreter, the outermost "reset" here
48 ; is already in its default position, so it doesn't need to be explicitly
51 (list "main content" 'i (list 'like (list 'the (damn2) 'boy)))
52 ; '(("side effect" bad) ("main content" i (like (the id boy))))
54 ; However, if you're executing this as a file, you would need to include explicit resets.
58 ; Instead of using reset/shift you could use an element like "print" in
59 ; building the side-effect, as we did in class. Here you wouldn't require an
60 ; explicit continuation, but as Chris said, that's because "print" already
61 ; represents an implicit continuation.
63 (define damn4 (lambda () (begin (print "bad") 'id)))
64 (list "main content" 'i (list 'like (list 'the (damn4) 'boy)))
65 ; "bad"'("main content" i (like (the id boy)))