(setq Q '(1 2 3 4)) ; (cond (list of expressions)) ; expression (conditional) (value to return) ; ; (car L) returns the first element of a list ; (cdr L) returns the rest of the list (except the first element) ; ; (cons X L) return a new list with X as the (car list) and L as the (cdr list) ; ; (plus a b) ; ; (1+ a) ; ; (mod X Y) ; ; (+-*/ X Y) ; (defun member (X L) (cond ((equal nil L) nil) ((equal X (car L)) t) (t (member X (cdr L))))) (defun max (L) (cond ((equal nil L) nil) ((equal nil (cdr L)) (car L)) (( > (car L) (max (cdr L))) (car L)) (t (max(cdr L))))) (defun min (L) (cond ((equal nil L) nil) ((equal nil (cdr L)) (car L)) (( < (car L) (min (cdr L))) (car L)) (t (min(cdr L))))) (defun fact (X) (cond (( < X 2) 1) (t (* X (fact (- X 1)))))) (defun length (X) (cond ((equal nil X) 0) (t (+ 1 (length (cdr X)))))) (defun sum (L) (cond ((equal nil L) 0) (t (+ (car L) (sum (cdr L)))))) (defun sum2 (L) (cond ((equal nil L) 0) (t (+ ( * (car L) (car L)) (sum2 (cdr L)))))) (defun std (L) (sqrt (float (- (sum2 L) (* (/ (sum L) (length L)) (/ (sum L) (length L))))))) (defun btree (V B) (cond ((equal nil B) (cons nil (cons V (cons nil nil)))) (( < V (car (cdr B))) (cons (btree V (car B)) (cdr B))) (t (cons (car B) (cons (car (cdr B)) (btree V (cdr (cdr B)))))))) (defun mkbtree (L) (cond ((equal nil L) nil) ((equal nil (cdr L)) (btree (cdr L) '())) (t (btree (car L) (mkbtree (cdr L)))))) (defun listdups (L) (cond ((equal nil L) nil) ((member (car L) (cdr L)) (cons (car l) (listdups (cdr L)))) (t (listdups (cdr L)))))