William James
6/7/2015 8:44:00 AM
Janis Dzerins wrote:
> edi@agharta.de (Dr. Edmund Weitz) writes:
>
> > Hi!
> >
> > I have a variable *PLACES* that holds a list of lists, like so:
> >
> > * (defparameter *places* '((1 2 3) nil nil (4 6) (8 5) (0) nil (7)))
> > *PLACES*
> >
> > I want each element of *PLACES* to be printed in reverse and on a line
> > of its own while preceded by its position in *PLACES*, i.e. I want
> >
> > 0: 3 2 1
> > 1:
> > 2:
> > 3: 6 4
> > 4: 5 8
> > 5: 0
> > 6:
> > 7: 7
> >
> > The following statement works fine, and I could just use it and be
> > happy with it:
> >
> > * (dotimes (i (length *places*))
> > (format t "~A:~{ ~A~}~%" i (reverse (nth i *places*))))
> > 0: 3 2 1
> > 1:
> > 2:
> > 3: 6 4
> > 4: 5 8
> > 5: 0
> > 6:
> > 7: 7
> > NIL
> >
> > But... - just out of curiosity - I'm asking myself if it would be
> > possible to get rid of the DOTIMES loop and have the positions
> > automatically be printed by a FORMAT statement that'll take *PLACES*
> > as its only format argument.
>
> DOLIST would be a better start.
>
> And extended LOOP:
>
> (loop
> for i upfrom 0
> for list in *places*
> do (format t "~&~A:~{ ~A~}~%" i (reverse list)))
Gauche Scheme:
(define places '((1 2 3) () () (4 6) (8 5) (0) () (7)))
(use srfi-42 :only (do-ec))
(do-ec (: list (index i) places)
(print i ":" (fold (pa$ format " ~a~a") "" list)))
===>
0: 3 2 1
1:
2:
3: 6 4
4: 5 8
5: 0
6:
7: 7
--
Under the disguise of liberalism, humanism, and democracy, Europeans have been
persuaded to commit racial suicide -- a race that has achieved so much and has
survived so much has been tricked into welcoming its own downfall and to take
active measures in order to become a stranger on its own soil.
www.kolumbus.fi/aquilon/moscowspeech2010.htm