R7RS-small: equivalence of quasiquoted expressions

67 Views Asked by At

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).

1

There are 1 best solutions below

0
On BEST ANSWER

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.