(* 1.9-lisp utilities. *) (gset define gset) (gset set gset) (define fact (lambda (& n) (if (= n 0) 1 (* n (fact (- n 1)))))) (= (fact 0) 1) (= (fact 5) 120) (define second (lambda (& x) (first (rest x)))) (define third (lambda (& x) (first (rest (rest x))))) (define fourth (lambda (& x) (first (rest (rest (rest x)))))) (define not (lambda (& x) (if x $f $t))) (define length (lambda (& s) (if (empty? s) 0 (+ 1 (length (rest s)))))) (define 1+ (lambda (& n) (+ n 1))) (define 1- (lambda (& n) (- n 1))) (define and (lambda x (if (empty? x) $t (if (first x) (and &. (rest x)) $f)))) (define or (lambda x (if (empty? x) $f (if (first x) $t (or &. (rest x)))))) (define map (lambda (& fn s) (if (empty? s) (&) (prep (fn (first s)) (map fn (rest s)))))) (define append (lambda x (if (empty? x) x (append-two-sequences (first x) (append &. (rest x)))))) (define append-two-sequences (lambda (& x y) (if (empty? x) y (prep (first x) (append-two-sequences (rest x) y))))) (define member (lambda (& x s) (if (empty? s) $f (if (= x (first s)) $t (member x (rest s))))))