4 ms·
This is fun. (loop :for animal :in '("dog" "cat" "bird") :for color :in '("brown" "black" "red") :do (format t "See the ~a ~a?~%" color animal)) S
by gruseom 14y ago
This is fun.
(loop :for animal :in '("dog" "cat" "bird")
:for color :in '("brown" "black" "red")
:do (format t "See the ~a ~a?~%" color animal))
See the brown dog?
See the black cat?
See the red bird?
How far can we take the example?
(loop :for animal :in '("dog" "cat" "bird")
:for color :in '("brown" "black" "red")
:for count :from 2
:do (format t "See the ~a ~a ~as?~%" count color animal))
See the 2 brown dogs?
See the 3 black cats?
See the 4 red birds?
How about this?
(loop :for animal :in '("dog" "cat" "bird")
:for color :in '("brown" "black" "red")
:for count :from 2 :sum count :into total
:do (format t "See the ~a ~a ~as?~%" count color animal)
:finally (format t "See all ~a?~%" total))
See the 2 brown dogs?
See the 3 black cats?
See the 4 red birds?
See all 9?
Anybody?
- jostmey 14y agoOkay, so I am impressed that you can also do this in lisp. I never really paid any attention to the language. Maybe it is worth checking out.
- gruseom 14y agoTo be fair, LOOP isn't really Lisp so much as an embedded DSL for loops that exists because of how easy Lisp makes embedded DSLs. People either love or hate Common Lisp's LOOP. Lispy types who prefer recursion often abhor it. I'm a lover.
- deleted 14y ago[deleted]