ITERATE

iterate is a lispy and extensible replacement for the LOOP macro.

It was written by Jonathan Amsterdam at MIT and recently ported to Common Lisp.

The canonical site for information about iterate is at http://common-lisp.net/project/iterate/.

Some examples:

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

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

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. (-:

The recent ASDF-installable package is at:

Download ASDF package from http://common-lisp.net/project/iterate/releases/iterate-current.tar.gz


language extension

Page in this topic: List Comprehension  


Also linked from: affi   asdf   cl-libxml2   cl-zmq   gtk-cffi   Lisp - Next Generation   Macro Characters   parser-combinators   SLIME-PPCRE  

CLiki pages can be edited by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively