Skip to content

Instantly share code, notes, and snippets.

@lenage
Created November 6, 2012 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lenage/4023199 to your computer and use it in GitHub Desktop.
Save lenage/4023199 to your computer and use it in GitHub Desktop.
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