From: Tim Vaughan Date: Sat, 5 Nov 2016 21:09:57 +0000 (+1300) Subject: Fixed if form when no alternative. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=scheme.forth.jl.git;a=commitdiff_plain;h=82b93d081309895fe1a8e446daad5b8a75896fa3 Fixed if form when no alternative. --- 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) diff --git a/scheme.4th b/scheme.4th index c300365..244a33f 100644 --- a/scheme.4th +++ b/scheme.4th @@ -1247,10 +1247,10 @@ hide env : if-consequent ( ifobj -- conseq ) cdr cdr car ; -: if-alternative ( ifobj -- alt|false ) +: if-alternative ( ifobj -- alt|none ) cdr cdr cdr nil? if - 2drop false + 2drop none else car then ;