# HG changeset patch # User Steve Losh # Date 1478015454 0 # Node ID d49a710b5fcc34c5eeb13e20b87a39b2785a147d # Parent 56f6ff3b225f518632ea8f86383373425ddca42c Simplify `for ... :in-array` iterate macro diff -r 56f6ff3b225f -r d49a710b5fcc losh.lisp --- a/losh.lisp Sat Oct 15 13:27:34 2016 +0000 +++ b/losh.lisp Tue Nov 01 15:50:54 2016 +0000 @@ -890,28 +890,28 @@ (print val)) " - (destructuring-bind (var &rest index-vars) + (destructuring-bind (var &rest index-vars + &aux (kwd (if generate 'generate 'for))) (ensure-list binding-form) - (with-gensyms (%i i arr dims floors) - (let ((kwd (if generate 'generate 'for))) - `(progn - (with ,arr = ,array) - ,@(when (some #'identity index-vars) - `((with ,dims = (coerce (array-dimensions ,arr) 'vector)) - (with ,floors = (calculate-array-floors ,arr)))) - ,@(iterate (for index :in index-vars) - (when index (collect `(with ,index = 0)))) - (generate ,%i :from 0 :below (array-total-size ,arr)) - (,kwd ,var next (progn - (let ((,i (next ,%i))) - ,@(iterate - (for index :in index-vars) - (for n :from 0) - (when index - (collect - `(setf ,index (mod (floor ,i (svref ,floors ,n)) - (svref ,dims ,n)))))) - (row-major-aref ,arr ,i))))))))) + (with-gensyms (i arr dims floors) + `(progn + (with ,arr = ,array) + ,@(when (some #'identity index-vars) + `((with ,dims = (coerce (array-dimensions ,arr) 'vector)) + (with ,floors = (calculate-array-floors ,arr)))) + (generate ,i :from 0 :below (array-total-size ,arr)) + ,@(iterate (for index :in index-vars) + (for dim-number :from 0) + (when index + (collect `(generate ,index :next + (mod (floor ,i (svref ,floors ,dim-number)) + (svref ,dims ,dim-number)))))) + (,kwd ,var :next + (progn + (next ,i) + ,@(iterate (for index :in index-vars) + (when index (collect `(next ,index)))) + (row-major-aref ,arr ,i))))))) (defun parse-sequence-arguments