diff options
Diffstat (limited to 'files/test-lambda.l')
-rw-r--r-- | files/test-lambda.l | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/files/test-lambda.l b/files/test-lambda.l index e088ad6..71ef0bd 100644 --- a/files/test-lambda.l +++ b/files/test-lambda.l @@ -4,20 +4,47 @@ '(a b ,((lambda (a) '(test . ,a)) 69) c d) -(define fib (lambda (c) (fib-rec 0 1 0 c))) -(define fib-rec (lambda (a b n c) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(define fib (lambda (c) (_fib 0 1 0 c))) +(define _fib (lambda (a b n c) (if (= n c) b - (fib-rec b (+ a b) (+ n 1) c)))) + (_fib b (+ a b) (+ n 1) c)))) + + -(define do (lambda (c f) (do-rec f 0 0 c))) -(define do-rec (lambda (f r n c) + +(define do (lambda (c f) (_do f '() 0 c))) + +(define _do (lambda (f r n c) (if (= n c) r - (do-rec f (f n) (+ n 1) c)))) + (_do f (cons (f n) r) (+ n 1) c)))) ;; comment ;; another comment ;; fib(13) -(do 10 (lambda (n) (display (fib n)))) ; comment +;(do 10 (lambda (n) (display (fib n)))) ; comment + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(define +list (lambda (l) (_+list l 0))) +(define _+list (lambda (l acc) + (if (nil? l) + acc + (_+list (cdr l) (+ acc (car l)))))) +(+list '(10 12)) + +(define * (lambda (a n) (+list (do n (lambda (n) a))))) + +(* 9 7) + +(define reverse (lambda (l) (_reverse l '()))) +(define _reverse (lambda (l n) + (if (nil? l) n + (_reverse (cdr l) (cons (car l) n))))) + +;; (+list (do 100 (lambda (n) (fib n)))) +(reverse (do 100 (lambda (n) (fib n)))) |