(require 'stdlib) ;; loops with let - temporary scoped functions (let loop ((xs '(a b c d e))) (cond ((null xs) nil) (t (puts (car xs)) (loop (cdr xs))))) (let loop ((xs '(a b c d e))) (when xs (puts (car xs)) (loop (cdr xs)))) (define (sum number) (let internal-sum ((n number) (total 0)) (cond ((zerop n) total) (t (internal-sum (1- n) (+ total n)))))) (puts (mapcar sum '(100 2000 30000))) (let loop ((i 0)) (if (< i 5) (progn (puts i) (loop (1+ i))))) ;; let*: bindings are installed as they are computer (let* ((foo 42) (bar foo)) (puts (and (= foo 42) (= bar 42)))) ; => t ;; letrec: the values of bindings are evaluated with all other ;; bindings in scope. This means that recursive functions may be ;; defined (define (f x) (letrec ((evenp (lambda (n) (if (= n 0) t (oddp (1- n))))) (oddp (lambda (n) (if (= n 0) nil (evenp (1- n)))))) (evenp x))) (puts (mapcar f '(0 1 2 3 4 5 6 7 8 9)))