Question

I'm used to (quote x) evaluating to x, (quote (x y z)) evaluating to (x y z), and (car (quote (x y z)) evaluating to x. The reasoning is simple: quote is a special form that does not evaluate its argument, but simply returns it as is.

I just started using Racket, and it thinks that (quote x) evaluates to (quote x), (quote (x y z)) evaluates to (quote (x y z)), and (car (quote (x y z)) evaluates to (quote x).

Well, actually, it prints these as 'x, '(x y z), and 'x, respectively, but that's the same thing.

Can someone explain the reasoning here? If, for some reason, (quote (x y z)) evaluates to (quote (x y z)), shouldn't the car of that then be quote? Where does (quote x) come from?

As far as I can tell, Racket, throughout the entire computation, internally behaves just as I'm used to, except that when it comes time to print the final result, it wraps it in a quote form. Is this correct in all cases? And if so, why would it want to do that?

No correct solution

OTHER TIPS

Racket evaluates the expressions in the same way as any Scheme. Racket however has in a special writer in the teaching languages. In DrRacket you can change the way values are printed. In the language menu, click the advanced button, and then take a look at the printing options.

Racket (language) prints out the result of top level forms, not only when entered in the interaction window (REPL), but always. It's to ease developing I guess and in real world applications you don't have statements that doesn't amount to anything so a real application wouldn't have these lines displayed since you have define and an expression to start your program and you could return (void) from it to force no output..

If you were to change language to either #!r6rs or #!r5rs you quickly see that the only way to get the result of an evaluation in the definitions window would be if you explicitly used display on the result.

No matter the language used, display displays it correctly. For a REPL-print the language and setting control how it displays. Standard #!racket is to display in such way that putting it in a new expression wrapped with display would print exactly the same as if you would have wrapped the original expression with display.

(define test 'hello-world)
(display test) ;; displays hello-world and not 'hello-world
test           ;; displays 'hello-world in #!racket, nothing in R6RS unless in interactions window
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top