From: Adam Warner
Subject: ITERATE-related advice
Date: 
Message-ID: <pan.2004.03.15.01.38.52.993182@consulting.net.nz>
Hi all,

I'm hacking Debian's cl-screamer package (and then I'll pass the fixes
onto Kevin Rosenberg). I've still got two compilation errors in the
primordial file:

; caught error:
;   (during macroexpansion of (defun test64-internal ...))
; Iterate, in (for i from 0 below n):
; No iterate function for this clause; do (display-iterate-clauses) to
; see the existing clauses.

; caught error:
;   (during macroexpansion of (defun test65-internal ...))
; Iterate, in (for i from 0 below n):
; No iterate function for this clause; do (display-iterate-clauses) to
; see the existing clauses.

These errors relate to these two functions:

(defun test64-internal (n)
 (let ((q (make-array (list n n)))
       (top t))
  (iterate (for i from 0 below n)
           (iterate (for j from 0 below n)
                    (setf (aref q i j) (make-variable))
                    (assert! (booleanpv (aref q i j)))))
  (iterate (for i from 0 below n)
           (for row = nil)
           (iterate (for j from 0 below n)
                    (setf row (orv row (aref q i j))))
           (setf top (andv top row)))
  (iterate (for j from 0 below n)
           (for column = nil)
           (iterate (for i from 0 below n)
                    (setf column (orv column (aref q i j))))
           (setf top (andv top column)))
  (iterate
   (for i from 0 below n)
   (iterate
    (for j from 0 below n)
    (iterate
     (for k from 0 below n)
     (if (/= j k)
         (setf top (andv top (notv (andv (aref q i j) (aref q i k))))))
     (if (/= i k)
         (setf top (andv top (notv (andv (aref q i j) (aref q k j))))))
     (if (and (/= k 0) (< (+ i k) n) (< (+ j k) n))
         (setf top
               (andv top (notv (andv (aref q i j) (aref q (+ i k) (+ j k)))))))
     (if (and (/= k 0) (< (+ i k) n) (>= (- j k) 0))
         (setf top
               (andv top (notv (andv (aref q i j) (aref q (+ i k) (- j k)))))))
     (if (and (/= k 0) (>= (- i k) 0) (< (+ j k) n))
         (setf top
               (andv top (notv (andv (aref q i j) (aref q (- i k) (+ j k)))))))
     (if (and (/= k 0) (>= (- i k) 0) (>= (- j k) 0))
         (setf top
               (andv top (notv (andv (aref q i j)
                                     (aref q (- i k) (- j k))))))))))
  (assert! top)
  (length
   (all-values
    (solution
     (iterate outer
              (for i from 0 below n)
              (iterate (for j from 0 below n)
                       (in outer (collect (aref q i j)))))
     (static-ordering #'linear-force))))))

(defun test64 () (= (test64-internal 8) 92))

(defun test65-internal (n)
 (let ((q (make-array (list n n))))
  (iterate (for i from 0 below n)
           (iterate (for j from 0 below n)
                    (setf (aref q i j) (make-variable))
                    (assert! (booleanpv (aref q i j)))))
  (iterate (for i from 0 below n)
           (for row = nil)
           (iterate (for j from 0 below n)
                    (setf row (orv row (aref q i j))))
           (assert! row))
  (iterate (for j from 0 below n)
           (for column = nil)
           (iterate (for i from 0 below n)
                    (setf column (orv column (aref q i j))))
           (assert! column))
  (iterate
   (for i from 0 below n)
   (iterate
    (for j from 0 below n)
    (iterate
     (for k from 0 below n)
     (if (/= j k)
         (assert! (notv (andv (aref q i j) (aref q i k)))))
     (if (/= i k)
         (assert! (notv (andv (aref q i j) (aref q k j)))))
     (if (and (/= k 0) (< (+ i k) n) (< (+ j k) n))
         (assert! (notv (andv (aref q i j) (aref q (+ i k) (+ j k))))))
     (if (and (/= k 0) (< (+ i k) n) (>= (- j k) 0))
         (assert! (notv (andv (aref q i j) (aref q (+ i k) (- j k))))))
     (if (and (/= k 0) (>= (- i k) 0) (< (+ j k) n))
         (assert! (notv (andv (aref q i j) (aref q (- i k) (+ j k))))))
     (if (and (/= k 0) (>= (- i k) 0) (>= (- j k) 0))
         (assert! (notv (andv (aref q i j) (aref q (- i k) (- j k)))))))))
  (length
   (all-values
    (solution
     (iterate outer
              (for i from 0 below n)
              (iterate (for j from 0 below n)
                       (in outer (collect (aref q i j)))))
     (static-ordering #'linear-force))))))

(defun test65 () (= (test65-internal 8) 92))


The errors appear to correspond with the latter part of each function:

     ...
     (iterate outer
              (for i from 0 below n)
              (iterate (for j from 0 below n)
                       (in outer (collect (aref q i j)))))

Is anyone familiar enough with the ITERATE package to see if this form is
misspecified? It appears to be related to the use of the OUTER label.

Version 1.2 of the ITERATE package is included with cl-screamer. I've
fixed it up to also work with SBCL, including building a new package to
provide DEFCONST functionality (which only evaluates the initial value of
a constant if the constant name is unbound).

Thanks,
Adam
From: Adam Warner
Subject: Re: ITERATE-related advice
Date: 
Message-ID: <pan.2004.03.15.02.28.32.761402@consulting.net.nz>
> The errors appear to correspond with the latter part of each function:
> 
>      ...
>      (iterate outer
>               (for i from 0 below n)
>               (iterate (for j from 0 below n)
>                        (in outer (collect (aref q i j)))))
> 
> Is anyone familiar enough with the ITERATE package to see if this form is
> misspecified? It appears to be related to the use of the OUTER label.

I believe I have tracked the issue down to iterate.lisp interning a few
symbols in lowercase in my build environment, and one of them includes
|in|. So there's no issue with the form itself. At first glance ITERATE
appears to be superior to LOOP. There's less confusion between nested and
parallel loops and Emacs can format the clauses.

Regards,
Adam