From 2466770c4ba4b1cf44894bce96cbf12434d4f4ed Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Tue, 14 Sep 2010 09:09:24 -0400 Subject: [PATCH 1/1] add damn3.rkt Signed-off-by: Jim Pryor --- damn3.rkt | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 damn3.rkt diff --git a/damn3.rkt b/damn3.rkt new file mode 100644 index 00000000..a087b4bc --- /dev/null +++ b/damn3.rkt @@ -0,0 +1,67 @@ +#lang racket +(require racket/control) + +(define damn0 (lambda () + 'id)) + +(define damn1 (lambda () + (cons '("side effect" bad) + 'id))) + +(define damn2 (lambda () (shift k + (cons '("side effect" bad) + (list (k 'id)))))) + +(define damn3 (lambda () (shift k + (list (k 'id) + '("side effect" bad))))) + + +; Now if we use damn0, our compositional semantics will work OK but +; we don't yet have any expressive contribution: + +(list "main content" 'i (list 'like (list 'the (damn0) 'boy))) +; '("main content" i (like (the id boy))) + + +; If we use damn1, we've added in the expressive 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 +; 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. + +; 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)))) + +; or to get the side effect at the end: + +(reset (list "main content" 'i (list 'like (list 'the (damn3) 'boy)))) +; '(("main content" i (like (the id boy))) ("side effect" bad)) + +; 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: + +(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. + + + +; 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. + +(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))) +; + -- 2.11.0