;; Konto mit 100 Mark (define balance 100) (define withdraw (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) 'not-enough-money))) ;; Konto mit lokalem Kontostand (define withdraw (let ((balance 100)) (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) 'not-enough-money)))) ;; Fabrik für Konten (define make-withdraw (lambda (balance) (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) 'not-enough-money)))) ;; Substitutionsmodell und referentielle Transparenz (define simple-make-withdraw (lambda (balance) (lambda (amount) (set! balance (- balance amount)) balance))) (define make-decrementer (lambda (balance) (lambda (amount) (- balance amount)))) ;; Fakultät rein funktional (define factorial (lambda (n) (letrec ((loop (lambda (fac count) (if (> count n) fac (loop (* count fac) (+ 1 count)))))) (loop 1 1)))) ;; Fakultät imperativ (define factorial (lambda (n) (let ((fac 1) (count 1)) (letrec ((loop (lambda () (if (> count n) fac (begin (set! fac (* count fac)) (set! count (+ 1 count)) (loop)))))) (loop)))))