7 ms·
talk about loop abuse: (flet ((make-random-move (rankf) (loop for place in places for rank = (funcall rank
by utx00 17y ago
talk about loop abuse:
(flet ((make-random-move (rankf)
(loop for place in places
for rank = (funcall rankf place)
collect (cons place rank) into ranks
sum rank into ranks-total
finally (loop with r = (if (zerop ranks-total) -1
(random ranks-total))
for (place . rank) in (shuffle ranks)
sum rank into current-ranks-total
when (< r current-ranks-total)
do (cond ((and (eq place ahead) (move ant)))
((eq place ahead-left)
(turn ant -1))
((eq place ahead-right)
(turn ant +1)))))))
(if (ant-food ant)
- sbt 17y agoYeah, this piece illustrates why Python is such a success and Lisp is not. Lambda may be the ultimate imperative, but certainly not the most convenient in many cases.
- itistoday 17y agoYou can write bad Python code too. Lisp is no longer one language, there are many Lisp variants that don't have CL's looping construct.
- calpaterson 17y agoLisp hasn't been "one language" for decades, and, by number, most lisp variants do not include the loop macro. It's just a popular dialect that does.
- tc 17y agoYou're not serious? The loop macro is the most Pythonic aspect of CL (c.f. list comprehensions). Your trouble handling that loop has nothing to do with lambdas.
- utx00 17y agoright, but i'm guessing his (and mine) trouble handling that loop has more to do with loop that it does with us - at least that's what i tell myself so please be gentle
- gamache 17y agoI'd call that loop use. This might as well be the poster child for why LOOP is an awesome macro.
- sketerpot 17y agoI've always loved how LOOP incorporates so many common looping idioms into one readable and writable form. It's ugly and hairy if you look at it closely, and certainly Iterate [1] is cleaner and more pleasing, but LOOP is still damn impressive. [1] http://common-lisp.net/project/iterate/ http://common-lisp.net/project/iterate/