Skip to content

Instantly share code, notes, and snippets.

@lenage

lenage/example.lsp

Created Nov 6, 2012
Embed
What would you like to do?
some common lisp stuffs
(defun our-copy-tree (tr)
(if (atom tr)
tr
(cons (our-copy-tree (car tr))
(our-copy-tree (cdr tr)))))
(defun get_max_v1 (lst)
(if (null lst)
"没有要比较的元素"
(if (null (cdr lst))
(car lst)
(if (> (car lst) (get_max_v1 (cdr lst)))
(car lst)
(get_max_v1 (cdr lst))))))
(get_max_v1 '())
(get_max_v1 '(123 465 32476 29715))
(get_max_v1 '(2 56 7 188 76 76 62))
(defun maximum (lst)
(if (null lst)
nil
(let ((tail-max (maximum (cdr lst))))
(if (> (car lst) tail-max)
(car lst)
tail-max))))
(maximum '())
(maximum '(123 465 32476 29715))
(maximum '(2 56 7 188 76 76 62))
(defun fac(n)
(if (= n 0)
1
(* n (fac (- n 1)))))
(defun fact(n)
(fac-s n 1))
(defun fac-s (n acc)
(if (= n 0)
acc
(fac-s (- n 1) (* acc n))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.