[CM] Forwarded: [ITERATE: old software, ported to the 21st century]

rm@fabula.de rm@fabula.de
Wed, 17 Dec 2003 18:26:44 +0100


I guess quite a few of use iterate over stuff once in a while :-)
I thought following post to the CLUMP list might be of interest to you.
I think someone allready works on a Debian package as well.
 
 Ralf Mattes

----- Forwarded message from Andreas Fuchs <asf@boinkor.net> -----

X-Original-To: clump@manly.caddr.com
X-Injected-Via-Gmane: http://gmane.org/
To: clump@manly.caddr.com
From: Andreas Fuchs <asf@boinkor.net>
Subject: [Clump] ITERATE: old software, ported to the 21st century

hi all,

For fun, I ported the ITERATE macro package from the CMU AI repository
(http://www-2.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/iter/iterate/0.html)
over to ANSI Common Lisp. In short, the ITERATE macro is an
extensible, more flexible and more lispy replacement for LOOP.

Some example code:

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

collects keys and items of an alist into two values

It also supports generators:

(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)))))

	  => ((B . 0) (C . 1))

(note also the liberal mixing of code and iterate clauses)

and allows easy finding of extrema:

(iterate (for elt in list-of-lists)
	 (finding elt maximizing (length elt)))

finds the longest list in a list of lists and generates pretty fast
code, too. (-:

There are more examples in the reference documentation in
doc/iter-man.ps, and a nice rant about LOOP (and more examples) in
doc/iterate-bare.ps (-:

You can find the code at
http://boinkor.net/lisp/iterate-ansi-0.9.1.tgz (MIT-licensed), and it
is ASDF-installable: (asdf-install:install 'iterate)

The original code was written by Jonathan Amsterdam. Kudos to him!
-- 
Andreas Fuchs, <asf@boinkor.net>, asf@jabber.at, antifuchs

_______________________________________________
Clump mailing list
Clump@caddr.com
http://manly.caddr.com/mailman/listinfo/clump

----- End forwarded message -----