1. Find the sequence of cars and cdrs that return x when applied to the following expressions:

    1. (a b x d)

      (car (cdr (cdr '(a b x d))))

    2. (a (b (x d)))

      (car (car (cdr (car (cdr '(a (b (x d))))))))

  2. What is the difference between the following s-expressions:

    1. (car (setq '(a b c)))

      Attempts to use '(a b c) as the name of a value to assign to and fails.

    2. (car '(setq '(a b c)))

      Returns setq as the front of a list consisting of the string setq and the quoted list '(a b c).

  3. Suppose you executed the following set of commands:

    (car (setq x '(a b c)))
    x (1)
    (setq x nil)
    (car '(setq x '(a b c)))
    x (2)

    What value of x would appear on the screen after:

    1. (1)?

      (a b c)

    2. (2)?

      nil

  4. Assign to the symbol x the list '(a b c). Use this to create the list '(a b c a b c).

    (setq x '(a b c)) (append x x)

  5. Write a function that replaces the first element of a list, i.e., (replace-first x y), replaces the first element of list y with the value of x.

    (defun replace-first (x y) (append (list x) (cdr y)))

  6. Write a recursive function power-of-two that computes the nth power of 2; e.g. (power-of-two 8) returns 256.

    (defun power-of-two (n)
     (cond ((= n 0) 1)
           ((> n 0) (* 2 (power-of-two (1- n))))
           ((< n 0) (/ 1.0 (power-of-two (- n))))))
  7. Write a non-recursive form of the same function, i.e., one that uses iterative constructs instead of recursion.

    (defun power-of-two (n)
     (do ((x 1 (+ x 1)) (sum 1))
         ((> x (abs n)) (cond ((< n 0) (/ 1.0 sum))
                               (t sum)))
         (setq sum (* 2 sum))))
  8. Write a recursive function count-atoms that counts the number of atoms that appear at all levels of an s-expression. For example:

    (defun count-atoms (list)
     (let ((count 0))
          (cond ((listp list) (dolist (x list) (setq count (+ count (count-atoms x)))))
                (t (setq count 1)))
          count))
  9. Given a map represented as a property list, write functions that, given a start-node and a goal-node, implement: