Subject: Re: Problem with iterate
From: (Rob Warnock)
Date: Wed, 28 Jul 2004 04:19:05 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
Rolf Wester  <> wrote:
| I wanted to try the iterate package but didn't get it to work.
| When I do the following (I'm running CMUCL18e):
|    (require 'asdf)
|    (push "./iterate-1.0.7/" asdf:*central-registry*)
|    (asdf:oos 'asdf:load-op :iterate)
|    (iterate (for i from 0 below 10)
|      (collect i))
| I get the error message:
|    Error in function C::DO-CALL:  Malformed iterate variable spec: COLLECT.
|        [Condition of type SIMPLE-ERROR]

Are you in the CL-USER package when you do that? If so, you should
note that CMUCL already comes with an EXTENSIONS:COLLECT macro, and
that EXTENSIONS is normally USE'd by CL-USER:

    > (describe 'collect)
    COLLECT is an external symbol in the EXTENSIONS package.
    Macro-function: #<Byte function (:MACRO COLLECT) {28FA5411}>
    Macro documentation:
      Collect ({(Name [Initial-Value] [Function])}*) {Form}*
      Collect some values somehow.  Each of the collections specifies
      a bunch of things which collected during the evaluation of the
      body of the form.  The name of the collection is used to define
      a local macro, a la MACROLET...

which can be used both as a collector and, with no args, to return the
collected result:

    > (let ((list '(1 3 4 2 6 5)))
	(collect ((odds)
		  (sum-odds 0 +)
		  (prod-twice-evens 1 *))
	  (dolist (i list)
	    (if (oddp i)
	      (progn (odds i) (sum-odds i))
	      (progn (evens i) (prod-twice-evens (* 2 i)))))
	  (values (odds) (sum-odds) (evens) (prod-twice-evens))))

    (1 3 5)
    (4 2 6)


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607