WJ wrote:
> Kent M Pitman wrote:
>
> > Looking at such an example, one might ask why WHEN is there at
> > all. But the answer turns out to be that it's very hard to
Kent M. Pitman wrote:
> It's unfortunate that the ability to define other loop-paths was
> omitted from the standard, since most implementations have such
> a thing. Some things I think you have to just code longhand.
>
> (loop with best-foo = nil ;untested
> for foo in (list foo1 foo2)
> when (or (not best-foo)
> (> (weight foo) (weight best-foo)))
> do (setq best-foo foo)
> finally (return best-foo))
>
> All in all, I think this is still pretty readable, though I'd accept
> the classic
>
> (let ((best-foo nil)) ;untested
> (dolist (foo (list foo1 foo2))
> (when (or (not best-foo)
> (> (weight foo) (weight best-foo)))
> (setq best-foo foo)))
> best-foo)
That doesn't look very Lispy to me, Kent.
Clojure:
user=> (max-key count "ah" "sleipnir" "see" "zebra")
"sleipnir"
user=> (apply max-key count ["ah" "sleipnir" "see" "zebra"])
"sleipnir"