4.33 Exercise 4.33
For the time being, quoted expressions will be turned into lazy lists via a syntactic transformation. It gets installed via a modified case in eval:
((quoted? exp) (let ((rest (cadr exp))) (if (list? rest) (eval (transformed-quotation rest) env) rest)))
transformed-quotation is not a very difficult function – essentially, it’s a left fold (or an accumulate) over the quoted expression that quotes every atom in the list (so as not to evaluate them) or recursively calls itself on lists. The expression that ends up being constructed is that of a list being contructed via nested conses.
(define (transformed-quotation exp) (accumulate (lambda (next acc) (list 'cons (if (list? next) (transformed-quotation next) (list 'quote next)) acc)) nil exp))