Is there any generic iteration contruct for sequences? Ideally it
would work just like DOLIST.
Example:
> (do-sequence (e "ab c")
(print e))
#\a
#\b
#\Space
#\c
nil
rodrigo vanegas
··@cs.brown.edu
In article <················@vegas.cs.brown.edu>, ··@cs.brown.edu (rodrigo vanegas) writes:
> Is there any generic iteration contruct for sequences? Ideally it
> would work just like DOLIST.
> > (do-sequence (e "ab c")
> (print e))
> #\a
> #\b
> #\Space
> #\c
> nil
Well, I don't know if you consider the LOOP macro to be Common Lisp, but
the following works in Allegro CL 4.2:
USER(20): (loop for x across "ab c" do (print x))
#\a
#\b
#\space
#\c
NIL
CLtL2 says that the "across" keyword works for iteration over arrays (vectors),
so it looks to be not quite as generic as over sequences. But it's close.
-- Don
--
Don Geddis (······@CS.Stanford.Edu)
My aunt gave me a walkie-talkie for my birthday. She says if I'm good, she'll
give me the other one next year. -- [Imitation] Steven Wright
(Don Geddis) writes:
>Well, I don't know if you consider the LOOP macro to be Common Lisp, but
>the following works in Allegro CL 4.2:
>
> . . .
>
>CLtL2 says that the "across" keyword works for iteration over arrays (vectors)
>so it looks to be not quite as generic as over sequences. But it's close.
Not to be a broken record, but the "iterate" macro (see my message from a
few days ago) includes:
(for var in-sequence sequence)
-- Josh Fisher
rodrigo vanegas writes:
> Is there any generic iteration contruct for sequences? Ideally it
> would work just like DOLIST.
>
> Example: (do-sequence (e "ab c") (print e))
You can write it yourself, roughly like this:
(defmacro dosequence ((var seqform &optional resultform) &body body)
(multiple-value-bind (body-rest declarations)
(parse-body body) ; splits off the declarations from the body
(setq declarations (if declarations `((DECLARE ,@declarations)) '()))
(let ((seqvar (gensym)))
`(BLOCK NIL
(LET ((,seqvar ,seqform))
(LET ((,var NIL))
,@declarations
; (DECLARE (IGNORABLE ,var))
(MAP NIL
#'(LAMBDA (,var) ,@declarations (TAGBODY ,@body-rest))
,seqvar
)
,resultform
) ) )
) ) )
Bruno Haible
······@ma2s2.mathematik.uni-karlsruhe.de
In article <················@vegas.cs.brown.edu> rodrigo vanegas,
··@cs.brown.edu writes:
>Is there any generic iteration contruct for sequences? Ideally it
>would work just like DOLIST.
Yes, it's called MAP. Try this:
(map nil #'print "ab c")
Tim Larkin
····@cornell.edu
607-255-7008
Is there anyone out there knows about a lisp - linear programming
package ?
Any information would be appreciated.
Thank you.
Meliani Suwandi
·······@sprecher.cs.uwm.edu
I'd be interested in any references to this also!
--
--
Mike Eggleston American Airlines Decision Technologies
(817)931-2287 P. O. Box 619616, MD 4462
(817)967-9763 (FAX) Dallas/Fort Worth Airport, Texas 75261-9616, USA