# HG changeset patch # User Steve Losh # Date 1550979987 18000 # Node ID ba5b4efb5872324e015061419d854ad2cab060c1 # Parent e844dad54ef313a3ef931ebf171000e8a49e5c9a Add iterate (for ... seed ... then ...) driver diff -r e844dad54ef3 -r ba5b4efb5872 package.lisp --- a/package.lisp Sat Feb 23 22:30:19 2019 -0500 +++ b/package.lisp Sat Feb 23 22:46:27 2019 -0500 @@ -351,6 +351,8 @@ :test :timing :within-radius + :seed + :then )) diff -r e844dad54ef3 -r ba5b4efb5872 src/iterate.lisp --- a/src/iterate.lisp Sat Feb 23 22:30:19 2019 -0500 +++ b/src/iterate.lisp Sat Feb 23 22:46:27 2019 -0500 @@ -665,3 +665,29 @@ (,kwd ,var = ,expr)))) +(defmacro-driver (FOR var SEED seed THEN then) + "Bind `var` to `seed` initially, then to `then` on every iteration. + + This differs from `(FOR … FIRST … THEN …)` and `(FOR … INITIALLY … THEN …)` + because `then` is evaluated on every iteration, *including* the first. + + Example: + + (iterate + (repeat 3) + (for x :first 0 :then (1+ x)) + (for y :initially 0 :then (1+ y)) + (for z :seed 0 :then (1+ z)) + (collect (list x y z))) + ; => + ((0 0 1) + (1 1 2) + (2 2 3)) + + " + (let ((kwd (if generate 'generate 'for))) + `(progn + (,kwd ,var :next ,then) + (initially (setf ,var ,seed))))) + +