Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 26 |
Nodes: | 6 (1 / 5) |
Uptime: | 01:15:57 |
Calls: | 483 |
Calls today: | 1 |
Files: | 1,073 |
Messages: | 97,851 |
Raffael Cavallaro wrote:
Indeed. Here's rob Warnock's version with the full boat of loop
keywords using triplets instead of an association list:
CL-USER 22 > (defun find-maximizing-item (list &key (key #'identity)
(test #'<))
(loop for item in list
for value = (funcall key item)
and position from 0
for current-triplet = (list item value position)
as max-triplet = current-triplet
then (if (funcall test (second max-triplet)
(second current-triplet))
current-triplet
max-triplet)
finally return
(values (first max-triplet) (second max-triplet) (third max-triplet))))
Rejected by ABCL:
Debugger invoked on condition of type PROGRAM-ERROR:
Indeed. Here's rob Warnock's version with the full boat of loop
keywords using triplets instead of an association list:
CL-USER 22 > (defun find-maximizing-item (list &key (key #'identity)
(test #'<))
(loop for item in list
for value = (funcall key item)
and position from 0
for current-triplet = (list item value position)
as max-triplet = current-triplet
then (if (funcall test (second max-triplet)
(second current-triplet))
current-triplet
max-triplet)
finally return
(values (first max-triplet) (second max-triplet)
(third max-triplet))))
FIND-MAXIMIZING-ITEM
CL-USER 28 > (find-maximizing-item (list "one" "two" "three" "fifteen" "four" "five") :key #'length)
"fifteen"
7
3