CMSC 471/671 Artificial Intelligence Fall 2000

Total Page:16

File Type:pdf, Size:1020Kb

CMSC 471/671 Artificial Intelligence Fall 2000

CMSC 471/671 Artificial Intelligence Fall 2000 Section 0101 TuTh 5:30 - 6:45pm MP103

Answer Keys for Homework 1

1. Which of the following S-expressions are atoms? Which of them are lists? A, “this is foo”, (), T, (1 2 3), 25, (sqrt 36), NIL Atoms: A, “this is foo”, (), T, 25, NIL List: (), (1 2 3), (sqrt 36), NIL 2. What will be returned when evaluating each of the following S-expressions? a) (mapcar #’= L1 (reverse L1)), where L1 has been assigned value (1 2 3) (NIL T NIL) b) (set y x), where x has been assigned value 5 but y has not Error message: y has not been assigned value c) (nth 1 ‘(a b c)) B 3. Using recursive definition to define a LISP function (union L1 L2) that returns the union of two sets represented as lists L1 and L2. Both L1 and L2 can be empty sets. (defun union (L1 L2) (cond ((null L1) L2) ((not (member (car L1) L2)) (cons (car L1) L2)) (t (union (cdr L1) L2)))) 4. Write a function (average L) that iteratively computes the average of a list of real numbers in list L. You may assume that L is non-empty. (defun average (L) (setq y 0) (dolist (x L) (setq y (+ x y))) (/ y (length L)))

Recommended publications