Backquote Exercises

  1. Rewrite the following functions to use backquote:
    ;;; X is a list, Y and Z are numbers:
    (define (f1 x y z)
      (cons 'a (append x '(b c) (list (+ y 1) (car x) (+ z 1) 'd))))
    
    ;;; x is a number
    (define (f2 x)
      (list 'a x (list 'b (+ x 1) 'c (+ x 2) 'd) 'e (+ x 4))) 
    
    ;;; x is a list
    (define (f3 x)
      (cons x x))
    
  2. Rewrite the following functions without backquote:
    ;;; x is a list, y and z are numbers
    (define (f4 x y z)
      `(x y z ,x ,y ,z p d q ,@x ,(+ y z) (+ ,y ,z) ,(cdr x)))
    
    ;;; x is a list
    (define (f5 x)
      `(1 ,@x 2 ,@x 3 ,@x 4))
    
    ;;; x is a number
    (define (f6 x)
      `(x is ,x which is half of ,(* x 2)))
    

Barak Pearlmutter <bap@cs.unm.edu>