(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
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 298 |
Nodes: | 16 (2 / 14) |
Uptime: | 26:08:15 |
Calls: | 6,680 |
Calls today: | 3 |
Files: | 12,222 |
Messages: | 5,342,184 |
Posted today: | 2 |