X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=scheme.forth.jl.git;a=blobdiff_plain;f=scheme-library.scm;h=62a7aa3513148f2bb39eaed311f2d7fb2d0297c4;hp=b92795dfd03f29005d13aa3ac9eb57e5abadbfb3;hb=82b93d081309895fe1a8e446daad5b8a75896fa3;hpb=7888f570d4b32b447622e25c38a4e78197cc7732 diff --git a/scheme-library.scm b/scheme-library.scm index b92795d..62a7aa3 100644 --- a/scheme-library.scm +++ b/scheme-library.scm @@ -29,11 +29,28 @@ ;; 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))) +(define method '(while (> counter 0) + (display counter) (newline) + (set! counter (- counter 1)))) + +(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)