Created
November 6, 2012 07:16
-
-
Save lenage/4023199 to your computer and use it in GitHub Desktop.
some common lisp stuffs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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