2017-03-06 11:00:18 -05:00
|
|
|
(defun mapcar (function-name the-list)
|
|
|
|
(if the-list
|
|
|
|
(cons
|
|
|
|
(funcall function-name (first the-list))
|
|
|
|
(mapcar function-name (rest the-list)))))
|
|
|
|
|
|
|
|
(defun maplist (function-name the-list)
|
|
|
|
(cond
|
|
|
|
((null the-list) nil)
|
|
|
|
(t (cons (funcall function-name the-list)
|
|
|
|
(maplist function-name (rest the-list))))))
|
|
|
|
|
2017-11-18 14:54:53 -05:00
|
|
|
(defun append (list-one list-two)
|
|
|
|
(append-tail (reverse list-one) list-two))
|
|
|
|
|
|
|
|
(defun append-tail (reversed-list list-two)
|
|
|
|
(if (null reversed-list) list-two
|
|
|
|
(recur (rest reversed-list) (cons (car reversed-list) list-two))))
|
|
|
|
|
|
|
|
(defun reverse (the-list)
|
|
|
|
(reverse-tail () the-list))
|
|
|
|
|
|
|
|
(defun reverse-tail (accumulator the-list)
|
|
|
|
(if (null the-list) accumulator
|
|
|
|
(recur (cons (first the-list) accumulator) (rest the-list))))
|
|
|
|
|
|
|
|
(defun deep-reverse (the-list)
|
|
|
|
(if the-list
|
|
|
|
(append
|
|
|
|
(deep-reverse (rest the-list))
|
|
|
|
(list
|
|
|
|
(if (listp (first the-list))
|
|
|
|
(deep-reverse (first the-list))
|
|
|
|
(first the-list))))))
|
2017-03-06 11:00:18 -05:00
|
|
|
|
|
|
|
(defun nth (n listA)
|
|
|
|
(cond
|
|
|
|
((equal 0 n) (first listA))
|
|
|
|
(t (nth (- n 1) (rest listA)))))
|