X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=scheme-library.scm;h=1a68a10d43a56e08ad417787677fe2629f3809d7;hb=fa6316fc696ddda325b2e2a8af83f4024ddf32bd;hp=b92795dfd03f29005d13aa3ac9eb57e5abadbfb3;hpb=050cc9a7e651ba8eacb054283307f4d06141c302;p=scheme.forth.jl.git diff --git a/scheme-library.scm b/scheme-library.scm index b92795d..1a68a10 100644 --- a/scheme-library.scm +++ b/scheme-library.scm @@ -29,11 +29,25 @@ ;; LIBRARY FORMS +(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)