From 76edead57b93fa867dd655c6fca3f759db1d0885 Mon Sep 17 00:00:00 2001 From: JeffBezanson Date: Fri, 20 Feb 2009 19:50:35 +0000 Subject: [PATCH] adding (do ) form --- femtolisp/system.lsp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/femtolisp/system.lsp b/femtolisp/system.lsp index 03da0d3..88a8b9f 100644 --- a/femtolisp/system.lsp +++ b/femtolisp/system.lsp @@ -424,6 +424,25 @@ (cdr clause))) clauses))))) +(define-macro (do vars test-spec . commands) + (let ((loop (gensym)) + (test-expr (car test-spec)) + (vars (map car vars)) + (inits (map cadr vars)) + (steps (map (lambda (x) + (if (pair? (cddr x)) + (caddr x) + (car x))) + vars))) + `(letrec ((,loop (lambda ,vars + (if ,test-expr + (begin + ,@(cdr test-spec)) + (begin + ,@commands + (,loop ,@steps)))))) + (,loop ,@inits)))) + (define-macro (dotimes var . body) (let ((v (car var)) (cnt (cadr var)))