



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The notes for lisp lab 3 in the elements of machine intelligence course offered by dr. A. Antonio arroyo at the university of florida during the fall 2008 semester. The lab covers the topics of optional parameters and functional arguments in lisp. Students will learn how to define procedures with optional parameters using the &optional keyword and how to handle functional arguments using funcall and apply.
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




1 EEL 5840 – Class #11 – Fall 2008^ University of Florida © Dr. A. Antonio Arroyo
Rous (^) Announcements
2 EEL 5840 – Class #11 – Fall 2008^ University of Florida © Dr. A. Antonio Arroyo
Rous (^) Today’s Menu
> Examples & Selected Homework 3 Solutions > Optional Parameters in LISP > Other Types of Parameters in LISP > Functional Arguments
3 EEL 5840 – Class #11 – Fall 2008^ University of Florida © Dr. A. Antonio Arroyo
Rous LISP Lab 2 - Examples
Are two SEXes equal? (defun EQAL (Sex1 Sex2) (cond ((ATOM Sex1) (EQ Sex1 Sex2)) ((ATOM Sex2) nil) ((EQAL (Car Sex1) (Car Sex2)) (EQAL (Cdr Sex1) (Cdr Sex2))) ))
4 EEL 5840 – Class #11 – Fall 2008^ University of Florida © Dr. A. Antonio Arroyo
Rous LISP Lab 2 - Examples
What is the depth of a list? (defun Depth (Lis) (Cond ((Null Lis) 0) ((Atom Lis) 0) ( t (max (+ (Depth (Car Lis)) 1) (Depth (Cdr Lis)) )) ))
5 EEL 5840 – Class #11 – Fall 2008^ University of Florida © Dr. A. Antonio Arroyo
Rous (^) Hwk 3 - Selected Solutions
Unnest (defun unnest (lis) (cond ((null lis) lis) ( (atom (car lis)) (cons (car lis) (unnest (cdr lis)))) ( t (append (unnest (car lis)) (unnest (cdr lis))))))
-or- (defun unnest (lis) (cond ((null lis) nil) ((atom lis) (list lis)) (t (append (unnest (car lis)) (unnest (cdr lis)) ))) ))
6 EEL 5840 – Class #11 – Fall 2008^ University of Florida © Dr. A. Antonio Arroyo
Rous (^) Hwk 3 - Selected Solutions
Setdiff (defun setdiff(s1 s2)(cond ((null s1) nil) ((member (car s1) s2) (setdiff (cdr s1) s2)) (t (cons (car s1) (setdiff (cdr s1) s2))) ))
7 EEL 5840 – Class #11 – Fall 2008^ University of Florida © Dr. A. Antonio Arroyo
Rous Hwk 3 - Selected Solutions
EQSet (defun eqset(s1 s2) (equal (setdiff s1 s2) (setdiff s2 s1)))
Makeset (defun makeset(lis)(cond ((null lis) nil) ((member (car lis) (cdr lis)) (makeset (cdr lis))) ( t (cons (car lis) (makeset (cdr lis)))) ))
8 EEL 5840 – Class #11 – Fall 2008^ University of Florida © Dr. A. Antonio Arroyo
Rous LISP Lab 3
13 EEL 5840 – Class #11 – Fall 2008^ University of Florida © Dr. A. Antonio Arroyo
Rous (^) LISP Lab 3
> (defun union2 (S1 S2 &optional (Ans)) (cond ( (null S1) (append Ans S2)) ( (member (car s1) S2) (union2 (cdr S1) S2 Ans)) ( 'else (union2 (cdr s1) S2 (append Ans (list (car S1))))) )) UNION > (union2 '(a b) '(c d)) (A B C D) > (union2 '(a) '(a b c d)) (A B C D) > (union2 '(a b) '(b c a)) (B C A)
14 EEL 5840 – Class #11 – Fall 2008^ University of Florida © Dr. A. Antonio Arroyo
Rous (^) LISP Lab 3
15 EEL 5840 – Class #11 – Fall 2008^ University of Florida © Dr. A. Antonio Arroyo
Rous LISP Lab 3
Rous LISP Lab 3
> (mymember '(a) '((a) (b))) NIL > (mymember '(a) '((a) (b)) :testfcn 'equal) ((A) (B)) > (mymember '(a) '((a) (b)) :testfcn 'eq) NIL
17 EEL 5840 – Class #11 – Fall 2008^ University of Florida © Dr. A. Antonio Arroyo
Rous