GRID-GENERATORS and GRID-ITERATE packages
I often find myself wanting to iterate over the points in a rectangular region of a grid in an arbitrary number of dimensions. If my grid is only one-dimensional or two-dimensional then I often just write nested loops to traverse the points of interest.
:do (loop :for x :from 0 :to 10 :by 1/2
:do (something x y)))
However, when I want the code to be flexible in the number of dimensions, I always end up writing application-specific code to increment arbitrarily long lists of integers with given bounds. I finally got sick of repeating this code every time I needed it and created a library.
For the particular application that I have in mind though, I wanted more than just walking the points inside some rectangular hyper-prism. I wanted to traverse all of the points at a give taxicab distance from a starting point.
GRID-GENERATORS package facilitates generating points in a rectangular hypergrid, generating points based on taxicab distance, and generating points based upon the number of steps in an arbitrary lattice (given the generators of the fundamental parallelpiped of the lattice). The
GRID-ITERATE package provides
ITERATE clauses for those generators.
For example, one could iterate over the same points in my nested example above like this:
:for (x y) := (funcall generator)
:do (something x y))
Or, with iterate:
(iterate:for point on-grid-to '(10 10) by '(1/2 1/2))
(destructuring-bind (x y) point
(something x y)))
LIST-TYPES package provides a way to generate `SATISFIES` type clauses that ensure that a list contains elements all of the given type. For example, if I wanted to ensure that my list was entirely rational numbers, I could use the declaration: