(define fibo (lambda (n) (if (= n 1) '(1) (if (= n 2) '(1 1) (let ((last (fibo (- n 1)))) (cons (+ (car last) (cadr last)) last)))))) (define unique (letrec ((contains? (lambda (lst val) (cond ((null? lst) #f) ((= (car lst) val) #t) (else (contains? (cdr lst) val)))))) (lambda (lst) (if (null? lst) lst (let ((ulst (unique (cdr lst)))) ; Gah, this should be tail recursive (if (contains? ulst (car lst)) ulst (cons (car lst) ulst))))))) (define stable-unique (lambda (lst) (reverse (unique (reverse lst))))) (define remove-duplicates stable-unique) (define transpose (lambda (lst) (apply map list lst))) (define position (letrec ((position-acc (lambda (lst val acc) (cond ((null? lst) #f) ((= (car lst) val) acc) (else (position-acc (cdr lst) val (+ acc 1))))))) (lambda (lst val) (position-acc lst val 0)))) (define-macro lambda-optional (lambda (argspec optionals . body) (let ((optnames (append '(self) argspec (map car optionals))) (optvals (append argspec (map cadr optionals))))() `(letrec ((+with-optionals (lambda ,optnames ,@body))) (lambda ,argspec (+with-optionals +with-optionals ,@optvals)))))) (define-macro m1 (lambda (args . body) `(lambda ,args ,@body))) (define-macro m2 (lambda (args . body) `(quote (lambda ,args ,@body))))