Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 23 |
Nodes: | 6 (0 / 6) |
Uptime: | 52:44:00 |
Calls: | 583 |
Files: | 1,139 |
D/L today: |
179 files (27,921K bytes) |
Messages: | 111,617 |
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:
Current LOOP context: "A compound form was expected, but ~S found.".
Rejected by SBCL:
; in: LAMBDA NIL
; (LOOP FOR ITEM IN LIST
; FOR VALUE = (FUNCALL KEY ITEM)
; AND POSITION FROM ...)
;
; caught ERROR:
; (in macroexpansion of (LOOP FOR ITEM ...))
; (hint: For more precise location, try *BREAK-ON-SIGNALS*.)
; A compound form was expected, but RETURN found.
; current LOOP context: 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
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:
Current LOOP context: "A compound form was expected, but ~S found.".
Rejected by SBCL:
; in: LAMBDA NIL
; (LOOP FOR ITEM IN LIST
; FOR VALUE = (FUNCALL KEY ITEM)
; AND POSITION FROM ...)
;
; caught ERROR:
; (in macroexpansion of (LOOP FOR ITEM ...))
; (hint: For more precise location, try *BREAK-ON-SIGNALS*.)
; A compound form was expected, but RETURN found.
; current LOOP context: FINALLY RETURN (VALUES (FIRST MAX-TRIPLET)
; (SECOND MAX-TRIPLET)
; (THIRD MAX-TRIPLET)).
3. Loop is very powerful, granted, and many people are trying to
argue that "you can do so much with loop that it's unreadable."
This is not an argument.
B. Pym wrote:
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:
Current LOOP context: "A compound form was expected, but ~S found.".
Rejected by SBCL:
"fifteen"
7
3
"ullalume"--
8
2