Professional Documents
Culture Documents
Solution2 Lisp
Solution2 Lisp
;;
;; Tail Recursions
;;
(defun fast-triangular-aux (N A)
"Compute the product of A and the N'th triangular number."
(if (= N 1)
A
(fast-triangular-aux (1- N) (+ N A))))
(defun fast-power (B E)
"Raise B to the E'th power."
(fast-power-aux B E 1))
(defun fast-power-aux (B E A)
"Compute the product of A and the E'th power of B."
(if (zerop E)
A
(fast-power-aux B (1- E) (* B A))))
(defun fast-list-length-aux (L A)
"Compute the sum of A and the length of list L."
(if (null L)
A
(fast-list-length-aux (rest L) (1+ A))))
;;
;; Lambda Expressions
;;
(defun apply-func-list (L X)
"Apply a list L of functions to object X."
(if (null L)
X
(funcall (first L) (apply-func-list (rest L) X))))
;;
;; Search Iteration
;;
;;
;; Filter Iteration
;;
(defun list-remove-if (P L)
"Return a list containing all elements of list L except for those satisfying
predicate P."
(if (null L)
nil
(if (funcall P (first L))
(list-remove-if P (rest L))
(cons (first L) (list-remove-if P (rest L))))))
;;
;; Functions Returning Multiple Values
;;