Commit e85d75dc authored by Liam M. Healy's avatar Liam M. Healy
Browse files

Fix iterate extension to increment properly

In the iterate extension :matrix-element, the first element of
following rows was repeated due to an error in the logic of the
expansion. 
Example: 
(defparameter m1 #m(1 2 3 ^ 0 6 8))
(iter:iter (iter:for e :matrix-element m1) (princ e) (princ " "))
1.0 2.0 3.0 0.0 0.0 6.0 8.0
This is now fixed.

Problem reported on SO, and sent to mailing list by Joshua Taylor.
parent 8644ef5c
;; Iterate
;; Norman Werner 2009-05-26 22:23:40EDT iterate.lisp
;; Time-stamp: <2011-08-20 17:36:47EDT iterate.lisp>
;; Time-stamp: <2013-06-23 22:46:42EDT iterate.lisp>
;;
;; Copyright 2009 Norman Werner, Liam M. Healy
;; Copyright 2009, 2013 Norman Werner, Liam M. Healy
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
......@@ -80,28 +80,30 @@ As an example try:
(defmacro-driver (FOR element matrix-element matrix)
"Iterates over all (copied) elements in matrix"
(alexandria:with-unique-names (row-index col-index row-size col-size m)
(when generate
(error "Not yet implemented a generate clause for matrix-element."))
`(progn
(with ,m = ,matrix)
(with ,row-index = 0)
(with ,col-index = 0)
(with ,row-size = (first (grid:dimensions ,m)))
(with ,col-size = (second (grid:dimensions ,m)))
(for ,element
:next
(if (>= ,row-index ,row-size)
(terminate)
(if (>= ,col-index ,col-size)
(progn
(setf ,col-index 0)
(incf ,row-index)
(if (>= ,row-index ,row-size)
(terminate)
(grid:aref ,m ,row-index ,col-index)))
(prog1
(grid:aref ,m ,row-index ,col-index)
(incf ,col-index))))))))
(when generate
(error "Not yet implemented a generate clause for matrix-element."))
`(progn
(with ,m = ,matrix)
(with ,row-index = 0)
(with ,col-index = 0)
(with ,row-size = (first (grid:dimensions ,m)))
(with ,col-size = (second (grid:dimensions ,m)))
(for ,element
:next
(if (>= ,row-index ,row-size)
(terminate)
(if (>= ,col-index ,col-size)
(progn
(setf ,col-index 0)
(incf ,row-index)
(if (>= ,row-index ,row-size)
(terminate)
(prog1
(grid:aref ,m ,row-index ,col-index)
(incf ,col-index))))
(prog1
(grid:aref ,m ,row-index ,col-index)
(incf ,col-index))))))))
(defmacro-driver (FOR indexes matrix-element-index matrix)
"Iterates over the indexes in matrix. indexes is a list like (row-index-name
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment