AI hw3 - Tarak Trivedi ECE Dept Fall 09 UFID: 51837169...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Tarak Trivedi ECE Dept Fall 09 UFID: 51837169 EEL-5840 Elements of Machine Intelligence Fall 2009 Homework 3 Programming Assignment: I. T > ;;;;;;;;; ;;; Problem Statement : To define a MYLIST function that emulates exactly the same functionality ;;; as the built-in function LIST ;;; Function: MYLIST ;;; In the function definition we first check whether a list was entered or atom was passed as an ;;; argument. An atom will be displayed in a single parenthesis. ;;; However if a list of S-expressions is passed then we print the list with double parenthesis. ;;; (either null or with single element or with a list of S-expressions) ;;; This is achieved by CONsing the first and last of the list and then finally CONsing them with nil. (defun mylist(lis) (cond ( (atom lis) (cons lis nil) ) ( T (cons (cons (car lis) (cdr lis) ) nil ) ) )) MYLIST Test Cases: > (mylist 'a) (A) > (mylist ()) (NIL) > (mylist '(a s d f g)) ((A S D F G)) > (mylist '(abc nil xyz '())) ((ABC NIL XYZ (QUOTE NIL))) > (dribble) II. T > ;;;;;;;;; ;;;; Problem Statement: To define a function that replicates the same functionality as the APPEND ;;;; function built-in in LISP. ;;; Function: MYAPPEND ;;;;;;;;; ;;; In the above function two lists are taken as arguments since append function works only on LISTS. ;;; Let the list have any elements. We simply CONs the first of the list to rest of the elements ;;; by calling the recursive function. (defun myappend(L1 L2) (cond ((NULL L1) L2) ((NULL L2) L1) (T (CONS (CAR L1) (myappend (CDR L1) L2))) )) MYAPPEND Test Cases: > (myappend '() '(a abc nil AI)) (A ABC NIL AI) > (myappend '() '()) NIL > (myappend '(xyz) '(asd)) (XYZ ASD) > (myappend '(asd '123 ufl) '(nil 1 '())) (ASD (QUOTE 123) UFL NIL 1 (QUOTE NIL)) > (dribble) III T > ;;;;;;;;; ;;;; Problem Statement : To define a function that prints last element (symbol) of the list ;;;; similar to the function LAST provided in LISP....
View Full Document

This note was uploaded on 09/17/2009 for the course EEL 5840 taught by Professor Arroyo during the Fall '08 term at University of Florida.

Page1 / 11

AI hw3 - Tarak Trivedi ECE Dept Fall 09 UFID: 51837169...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online