From: Jonathan Amsterdam
Subject: Iterate
Date: 
Message-ID: <JBA.91Jul26144828@kix.ai.mit.edu>
This message is an advertisement for Iterate, an iteration macro I wrote
and have been using for several years.  This Iterate is not to be confused
with the Xerox Iterate.

My Iterate is for people who like doing iteration `a la loop, but who hate
Loop's parenless syntax and its lack of extensibility.  Iterate is
essentially loop with parens and a code-walker.  There are some other
features as well (generators, improved handling of nested loops, many
useful clauses like for...in-file and finding...maximizing), but the best
news is that you can write macros that turn into pieces of Iterate code.

Some examples:

	(iter (for i from 1 to 10)
	      (collecting i))

Loop users should have no trouble understanding this.  Note that the macro
name is "iter", not "iterate", both to save space and to avoid conflict
with the symbol "iterate", which may be sanctioned by Common Lisp.  (See
appendix to CLtL2, about series functions). 

	(iter (for (key val) on prop-list by #'cddr)
	      (let ((new-val (sqrt val)))
		(format t "~a: ~a~%" key new-val)
	        (collecting (cons key new-val))))

Destructuring, for...on...by are just like loop, but note that let and
format are the ordinary Lisp let and format--you can mix Lisp and Iterate
indiscriminately.  No need for "do", no separate language to learn.

	(defun 2d-array-to-list (array)
	  (iter outer
		(for i below (array-dimension array 0))
		(iter (for j below (array-dimension array 1))
		      (in outer (collecting (aref array i j))))))

The ability to label iterate forms, and the "in" special form, combine to
simplify operations involving nested loops.  As you probably know if you
have tried to write such code with Loop, without the "in" form, it is
either wrong or hard & messy.

	(defun square (x) (* x x))

	(defmacro summing-squares (x)
	  `(summing (square ,x)))

	(iter (for el in list)
	      (summing-squares x))

The iter body is walked and macros are expanded, so this works.  Iterate is
extensible with no more effort than writing a macro.  

Availability:

Via anonymous ftp to ftp.ai.mit.edu, in directory /com/ftp/pub:

iterate.lisp	iterate source code only
iterate.tar.Z   compressed tar file of source and documentation

Or I can email these things,

Or you can check your local AI library, if it gets other schools' TRs
(The Iterate Manual Is MIT AI Memo 1236).

Or I can snail-mail you the docs. 

Send me email if you want to be on the Iterate users' mailing list.

  
  	-Jonathan Amsterdam
	 ยทยทยท@ai.mit.edu