From 3d1e86f1638c71cfc4d11638dcb6b42cfd30d859 Mon Sep 17 00:00:00 2001 From: Ken Harris Date: Wed, 12 Jun 2013 19:24:12 -0700 Subject: [PATCH] Allow DO / DO* to take bare symbols as vars. --- src/boot.lisp | 14 ++++++++++---- tests/iter-macros.lisp | 32 ++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/boot.lisp b/src/boot.lisp index 16463e5..d7141f6 100644 --- a/src/boot.lisp +++ b/src/boot.lisp @@ -291,7 +291,9 @@ (defmacro do (varlist endlist &body body) `(block nil - (let ,(mapcar (lambda (x) (list (first x) (second x))) varlist) + (let ,(mapcar (lambda (x) (if (symbolp x) + (list x nil) + (list (first x) (second x)))) varlist) (while t (when ,(car endlist) (return (progn ,@(cdr endlist)))) @@ -299,13 +301,16 @@ (psetq ,@(apply #'append (mapcar (lambda (v) - (and (consp (cddr v)) + (and (listp v) + (consp (cddr v)) (list (first v) (third v)))) varlist))))))) (defmacro do* (varlist endlist &body body) `(block nil - (let* ,(mapcar (lambda (x) (list (first x) (second x))) varlist) + (let* ,(mapcar (lambda (x1) (if (symbolp x1) + (list x1 nil) + (list (first x1) (second x1)))) varlist) (while t (when ,(car endlist) (return (progn ,@(cdr endlist)))) @@ -313,7 +318,8 @@ (setq ,@(apply #'append (mapcar (lambda (v) - (and (consp (cddr v)) + (and (listp v) + (consp (cddr v)) (list (first v) (third v)))) varlist))))))) diff --git a/tests/iter-macros.lisp b/tests/iter-macros.lisp index a19fd16..8ec2a09 100644 --- a/tests/iter-macros.lisp +++ b/tests/iter-macros.lisp @@ -12,15 +12,31 @@ (= total 15))) ; DO -(test (do ((a 0 b) - (b 1 (+ a b)) - (n 0 (1+ n))) - ((= n 10) +(test (do ((a 0 b) + (b 1 (+ a b)) + (n 0 (1+ n))) + ((= n 10) (= a 55)))) +(test (= 5 + (do (x) (t 5)))) +(test (= 5 + (do ((x)) (t 5)))) +(test (= 5 + (do ((x nil)) (t 5)))) +(test (= 5 + (do ((x nil nil)) (t 5)))) ; DO* -(test (do* ((a 0 b) - (b 1 (+ a b)) - (n 0 (1+ n))) - ((= n 10) +(test (do* ((a 0 b) + (b 1 (+ a b)) + (n 0 (1+ n))) + ((= n 10) (= a 512)))) +(test (= 5 + (do* (x) (t 5)))) +(test (= 5 + (do* ((x)) (t 5)))) +(test (= 5 + (do* ((x nil)) (t 5)))) +(test (= 5 + (do* ((x nil nil)) (t 5)))) -- 1.7.10.4