December 17, 2003

Andreas Fuchs has ported ITERATE from the CMU AI repository to ANSI lisp: “In short, the ITERATE macro is an extensible, more flexible and more lispy replacement for LOOP.”

Andreas' port, is available under the MIT license at

Straightforward collecting:

(iterate (for (key . item) in alist)
	 (collect key into keys)
	 (collect item into items)
	 (finally (return (values keys items))))


(iterate (generate i from 0 to 6)
	 (for (key . value) in '((a . 2) (zero . 10) (one . 20) (d . 5)))
	 (when (>= value 10)
	   (collect (cons key (next i)))))

	  => ((ZERO . 0) (ONE . 1))

When other languages, with non-uniform syntaxes, add a feature like this the language developers add new keywords, users are forced to upgrade, and a flurry of articles are published on how to use the new facility. Sad.

Posted by jjwiseman at December 17, 2003 09:48 AM

The result for the second example is not, as Edi Weitz noted on the Cliki page lready, '((B . 0) (C . 1)), but ((ZERO . 0) (ONE . 1)).

I guess that's what you get when you modify examples and don't run them again (-:

Posted by: Andreas Fuchs on December 17, 2003 12:35 PM

Thanks, Andreas, it's fixed now. That's what I get for not even loading the code...

Posted by: John Wiseman on December 17, 2003 01:53 PM

Hi! Maybe off-topic, but here it comes: Is there any "standard" way of finding where a maximum/minimum of a sequence is? I mean, there is a native "max" in Lisp that founds a maximum; and there is "loop...maximize" or "iterate...maximize".

I'm looking for a kinda "argmaximize". I'm at present hacking the "cl" Emacs Lisp package, intending that the construct "loop for Xi being the elements of X using (index i)" admits a clause "argmaximizing i Xi into var" so "var" holds the "i" where "Xi" is maximum.

"Iterate" code seems quite clean, in order to try the same thing.

Bye, and thanks for Lemonodor.

Posted by: C Artime on December 18, 2003 11:58 AM

It's not clear to me from your posting if you're aware of the fact that iterate can do that already, so here goes:

* (iter (for x below pi by .0001) (finding x maximizing (sin x)))


Posted by: Edi Weitz on December 18, 2003 04:08 PM

And of course you can do pretty much the same thing with loop:

cl-user(1): (loop for x below pi by .0001 maximizing (sin x))

Posted by: waiter on December 18, 2003 06:32 PM

Ops, I was not aware of "iterate"'s "finding" clause. I should have read more carefully its code before posting (and Cliki: But I fail to see the "argmax" point in Waiter's "loop" example.

Thank you very much.

Posted by: C Artime on December 18, 2003 10:40 PM

My mistake. It was a bit late and I didn't read your question carefully enough. Sorry.

Posted by: waiter on December 19, 2003 12:51 AM

Surely my bad English did help, too.

Posted by: C Artime on December 19, 2003 05:34 AM
Post a comment

Email Address:


Unless you answer this question, your comment will be classified as spam and will not be posted.
(I'll give you a hint: the answer is “lisp”.)


Remember info?