<html><head><base href="x-msg://52/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Sep 18, 2011, at 4:41 PM, Racket Noob wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div class="hmmessage" style="font-size: 10pt; font-family: Tahoma; "><div dir="ltr">Ok, maybe this is not something that's important in other programming languages, but it *is* important in lisps. As a lisp educator, how can you *not* to teach this fundamental fact about lisp?<br></div></div></span></blockquote></div><div><br></div>Two questions:<div>1) How many people here are Lisp educators? Most of us seldom if ever use Lisp, but use Racket every day.<br></div><div>2) Is "representing expressions as lists" really a fundamental fact about Lisp, or is it an implementation decision taken by some of the early implementers of Lisp?</div><div><br></div><div>Actually, in many ways I sympathize: when I first encountered Racket (which was then called PLT Scheme), I took a similar interpreter-based approach to understanding what it was doing (having previously encountered Lisp and learned the same "expressions are lists" dictum you learned). It turns out not as helpful as one would think.</div><div><br></div><div>In fact, the Racket reader does NOT represent expressions as lists; it represents them as "syntax objects", which (as I understand it) can be nested in the same way lists can, but carry some additional information. So when you type the eight characters "'(1 2 3)", what happens?</div><div>1) The reader converts this into a syntax object containing "quote" and a nested syntax object containing "1", "2", and "3".</div><div>2) The evaluator converts this into an internal representation of a list containing 1, 2, and 3</div><div>3) The printer converts this into the eight characters "'(1 2 3)"</div><div><br></div><div><blockquote type="cite"><span class="Apple-style-span" style="font-family: Tahoma; font-size: 13px; ">I don't understand why you (i.e. Racket implementers) choose Racket by default prints list this way.</span></blockquote><br></div><div>In part because of our experience in the classroom. For beginners, it's convenient for the read-eval-print sequence to be idempotent, i.e. if you do it twice, you get the same result as if you had done it once. In other words, anything you get as an answer to a question can be copied and pasted back in, and you'll get it again. And you're right, that was NOT true of classic Lisp. Suppose the variable y has the value (list '+ 3 4); then if I type the two characters "'y" into a REPL, I get the one character "y"; if I type the one character "y" into the REPL, I get the seven characters "(+ 3 4)"; and if I type this into the REPL, I get the one character "7".</div><div><br></div><div>In our experience, this confuses students, so we use an analogy more like arithmetic or algebra. Don't think of the operation as "evaluating" but rather "simplifying as far as possible." In grade-school arithmetic, suppose x has the value 5, and I want to simplify "3 + 4x". It simplifies to 3 + 4*5, which simplifies to 3 + 20, which simplifies to 23, which doesn't simplify any farther. We've seen four different expressions along the way, but they all simplify to 23.</div><div><br></div><div>Now let's do that in Racket. Suppose variable x has the value 5, and I type</div><div>(+ 3 (* 4 x))</div><div>This is simplified to (+ 3 (* 4 5)), which is then simplified to (+ 3 20), which is then simplified to 23, which can't be simplified any farther. I can type any of these four expressions into a REPL, and I get the exact same result.</div><div><br></div><div>Now let's try this with lists, the way DrRacket does it by default. I type in</div><div>(cons 1 (list 2 3 x))</div><div>which is simplified to (cons 1 (list 2 3 5)), which is then simplified to (list 1 2 3 5) (or, if you prefer, (cons 1 (cons 2 (cons 3 (cons 5 empty)))), which can't be simplified any farther. I can type any of these four expressions into a REPL, and I get the exact same result.</div><div><br></div><div>Now let's try it the way you're thinking about it. I type in</div><div>(cons 1 (list 2 3 x))</div><div>which is read as (list 'cons 1 (list 'list 2 3 'x)), which after one step of reduction produces (list 'cons 1 (list 'list 2 3 5)), which after another step of reduction produces (list 'cons 1 (list 2 3 5)), which after another step of reduction produces (list 1 2 3 5), which you want to print out as (1 2 3 5). We've seen six different expressions. Typing these six different expressions into a REPL gives you five different answers, one of which is an error message.</div><div><br></div><div>Does that help?</div><br><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Stephen Bloch</div><div><a href="mailto:sbloch@adelphi.edu">sbloch@adelphi.edu</a></div></div></span></span>
</div>
<br></body></html>