[iterate-devel] Fwd: if-first-iteration, a little better vers ion as an arch patch

Attila Lendvai attila.lendvai at gmail.com
Sun Jan 29 22:18:56 UTC 2006


> The user API looks ok, however the way you change add-binding removes safety checks: several uses must have the same default initialization and type, etc.  This could cause future extensions to break.

I don't really see what you mean here (newbie warning repeated :)

I modified add-binding to accept an optional keyword param,
:reuse-existing. It does not change anything anywhere, except you can
optionally tell it not to error when such a variable is already
defined. And that is exactly what i need for first-iteration-p: i want
a lazy added, shared variable for each use of first-iteration-p.

For first-time-p i use the usual make-var-and-binding, because there i
need to create a new variable for each uses.

> I think the make-xyz-binding API should be used, that's what they are for, and they also provide for the optional type declarations.  I agree the many make-*-binding are confusing.  It's also confusing me every time!

Maybe a make-shared-binding is what's missing?

> <     (locally (declare (optimize safety ...
> >     (locally (declare (optimize (safety 3)...
>
> While I can indeed remember a bad declaration (revealed by sbcl/cmucl) somewhere in the testsuite fixed on 2005-05-20, the above change is not necessary.  SAFETY just means (SAFETY 3).  It's been there since CLtL1.  See CLHS about OPTIMIZE.

Right. It is sbcl 0.9.7 complaining, I'll try the newest and report
the bug to the developers if it still persists.

IIRC my only useful addition to iterate-tests.lisp was the two tests:

(deftest first-time-p.1
    (iter (for i to 5)
          (if (first-time-p) (collect -1))
          (if (first-time-p) (collect -2))
	  (when (oddp i)
	    (if (first-time-p) nil (collect -1))
	    (collect i)))
  (-1 -2 1 -1 3 -1 5))

(deftest first-iteration-p.1
    (iter (for i to 5)
          (if (first-iteration-p) (collect -1))
          (if (first-iteration-p) (collect -2))
	  (when (oddp i)
	    (if (first-iteration-p) nil (collect -1))
	    (collect i)))
  (-1 -2 -1 1 -1 3 -1 5))

- attila

(alias 101 on irc &no 'its not lisp code :)



More information about the iterate-devel mailing list