-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab2.lisp
48 lines (43 loc) · 1.09 KB
/
lab2.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
;; Samuel Savage
;; CIS667 Fall 2016
;; Lab 02 20160916
;; written by Professor Lee for AI-16
(defun my-list (&rest args)
(cond
((eq args nil) nil)
(t (cons (car args) (cdr args)))
)
)
;; skeleton written by Professor Lee for AI-16
(defun my-reverse (arg)
(cond
((eq arg nil) nil)
((eq (cdr arg) nil) (cons (car arg) nil))
( t (append (my-reverse (cdr arg)) (cons (car arg) nil)))
)
)
;; skeleton written by Professor Lee for AI-16
(defun my-append (lst1 lst2)
(cond
((eq lst1 nil) lst2)
((eq lst2 nil) lst1)
( t (cons (car lst1) (my-append (cdr lst1) lst2)))
)
)
;; takes a list L of atoms and an atom A, removing A from L
(defun my-remove (L A)
(cond
((eq L nil) '())
((eq (car L) A) (my-remove (cdr L) A))
( t (cons (car L) (my-remove (cdr L) A)))
)
)
;; takes a list L of atoms, an atom A, and an atom B
;; replacing all occurrences of A with B
(defun my-replace (L A B)
(cond
((eq L nil) '())
((eq (car L) A) (my-replace (cons B (cdr L)) A B))
( t (cons (car L) (my-replace (cdr L) A B)))
)
)