ITERATE: old software, ported to the 21st century
Andreas Fuchs <[email protected]> Tue, 16 Dec 2003 23:01:35 +0100
| Newsgroups | gmane.lisp.clump |
|---|---|
| Message-ID | <86vfogifr4.wl%[email protected]> |
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, <[email protected]>, [email protected], antifuchs