Lecture #3: In Class Activity

Solution Key


Problem 1

(defun circle-info (radii-list)
 (mapcar #'(lambda (x)
            (cons (* 2 pi x)
                  (* pi x x)
            )
           )
         radii-list
 )
)


Problem 2

(defun convert (x)
 (and (listp x)
      (convert-helper 0 (make-array (length x)) x)
 )
)

(defun convert-helper (num arr lst)
 (if (null lst)
  ;then
  arr
  ;else
  (progn
   (setf (aref arr num) (car lst))
   (convert-helper (+ num 1) arr (cdr lst))
  )
 )
)


Problem 3

  1. (defstruct right-triangle
     a
     b
     (c (sqrt (+ (* a a) (* b b))))
    )
    
  2. (defun isocles-p (x)
     (and (right-triangle-p  x)
          (= (right-triangle-a x)
             (right-triangle-b x)
          )
     )
    )
    


Problem 4

See Activity #4 for solution.


Back to main page...