简体   繁体   中英

R7RS-small: equivalence of quasiquoted expressions

The R7RS-small standard , section 4.2.8 Quasiquotation on page 20-21 says that

(let ((a 3)) `((1 2) ,a ,4 ,'five 6))

is equivalent to

  • `((1 2) 3 4 five 6)

and

  • (let ((a 3)) (cons '(1 2) (cons a (cons 4 (cons 'five '(6))))))

But not equivalent to:

(let ((a 3)) (list (list 1 2) a 4 'five 6))

How can the expression above be any different from the first three? All four expressions above evaluate to the same thing: '((1 2) 3 4 five 6) .

The reason is given a few lines before the example (emphasis is mine):

A quasiquote expression may return either newly allocated, mutable objects or literal structure for any structure that is constructed at run time during the evaluation of the expression. Portions that do not need to be rebuilt are always literal.

This means that in:

(let ((a 3)) `((1 2) ,a ,4 ,'five 6))

the part (1 2) inside the quasiquote must be treated as a literal, as in ...'(1 2)... and not as a structure built from its components, like in: ...(list 1 2)... .

This seems to be an overspecification, since '(1 2) prints exactly like (list 1 2) , but the first list cannot be mutated (or, better, there is an undefined behaviour if mutated), while the second one can be legally mutated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM