X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=scheme-library.scm;h=1a68a10d43a56e08ad417787677fe2629f3809d7;hb=fa6316fc696ddda325b2e2a8af83f4024ddf32bd;hp=dc345cf7e7d688ea11cd1a0b043d092f74814d89;hpb=9b75e5d50017b95ee8d10ade294c6676a1a60af4;p=scheme.forth.jl.git diff --git a/scheme-library.scm b/scheme-library.scm index dc345cf..1a68a10 100644 --- a/scheme-library.scm +++ b/scheme-library.scm @@ -28,11 +28,26 @@ (append (reverse (cdr l)) (list (car l))))) ;; LIBRARY FORMS -(define-macro (let value . body ) - (list (list 'lambda (list (car value)) body)) (cdr value)) + +(define-macro (while condition . body) + `(begin + (define (loop) + (if ,condition + (begin ,@body (loop)))) + (loop))) ;; TESTING +(define-macro (backwards . body) + (cons 'begin (reverse body))) + +; Test for the while macro. +(define (count) + (define counter 10) + (while (> counter 0) + (display counter) (newline) + (set! counter (- counter 1)))) + ; Basic iterative summation. Run this on large numbers to ; test garbage collection and tail-call optimization. (define (sum n)