Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

#'reduce

9 views
Skip to first unread message

Robert L.

unread,
Dec 9, 2017, 2:09:55 AM12/9/17
to
> >> (reduce #'max '("This" "is" "a" "test" ".") :key #'length)
> >>
> >
> >Reduce doesn't accept :KEY according to CLtL2. In fact, if you
> >look at REDUCE more closely, you'll see that :KEY wouldn't make sense.
> >
> >Instead of REDUCE, try the following:
> >
> >(APPLY #'MAX (MAPCAR #'LENGTH '("This" "is" "a" "test" ".")))
> >
> >Even more efficient would be:
> >
> >(LET ((max 0))
> > (DOLIST (elt '("This" "is" "a" "test" "."))
> > (SETF max (MAX max (LENGTH elt))))
> > max)
> >
>
> Macintosh Common Lisp (MCL) accepts the :key keyword parameter:
> ? (reduce #'max '("This" "is" "a" "test" ".") :key #'length)
> 4
>
> You can also use loop to make it clearer:
> ? (loop for el in '("This" "is" "a" "test" ".")
> maximizing (length el))
> 4

(require srfi/42) ; max-ec

(max-ec (:list x '("This" "is" "a" "test")) (string-length x))

===>
4


--
[T]hey always try to undermine our sense of identity ... while at the same time
they have ... stories, even in the New York Times, how Jews are ... like fourth
or fifth cousins.... It has just come out ... DNA testing companies ... admit
adding fake African ancestry to White profiles in order to screw with
"racists".... When you look at the people who own these companies, they're not
on our side---they're here to destroy us. http://archive.org/details/nolies
https://archive.org/details/Duke.20171208
0 new messages