Why does the Racket interpreter write lists with an apostroph before?
Asked Answered
P

1

2

Why is '(1 2 3) written instead of (1 2 3) ?

> (list 1 2 3)
'(1 2 3)
Perimorph answered 8/4, 2016 at 20:4 Comment(1)
(list 1 2 3) should return (1 2 3). Printing '(1 2 3) is incorrect.Engraving
R
5

Racket's default printer prints a value as an expression that would evaluate to an equivalent value (when possible). It uses quote (abbreviated ') when it can; if a value contains an unquotable data structure, it uses constructor functions instead. For example:

> (list 1 2 3)
'(1 2 3)
> (list 1 2 (set 3))   ;; sets are not quotable
(list 1 2 (set 3))

Most Lisps and Schemes print values using the write function instead. You can change Racket's printer to write mode using the print-as-expression parameter, like this:

> (print-as-expression #f)
> (list 1 2 3)
(1 2 3)

See the docs on the Racket printer for more information.

Recount answered 8/4, 2016 at 21:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.