From 82b93d081309895fe1a8e446daad5b8a75896fa3 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Sun, 6 Nov 2016 10:09:57 +1300 Subject: [PATCH] Fixed if form when no alternative. --- scheme-library.scm | 17 +++++++++++++++++ scheme.4th | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) 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 ; -- 2.20.1