Re: Am I missing something about (loop ... maximizing ...) ?

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Am I missing something about (loop ... maximizing ...) ?
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.scheme
Date : 08. Sep 2024, 09:03:27
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vbji7r$1rikb$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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:

Rejected by SBCL:

;    A compound form was expected, but RETURN found.
;   current LOOP context: FINALLY RETURN (VALUES (FIRST MAX-TRIPLET)
;                                                (SECOND MAX-TRIPLET)
;                                                (THIRD MAX-TRIPLET)).

Gauche Scheme

(use srfi-1) ;; second

(define (maximizing-item the-list :key (key identity))
  (fold
    (lambda (item i best)
      (let ((value (key item)))
        (if (or (null? best) (> value (second best)))
          (list item value i)
          best)))
    '()
    the-list
    (lrange 0)))

(maximizing-item '("bells" "usher" "ullalume" "poe") :key string-length)
  ===>
("ullalume" 8 2)

Date Sujet#  Auteur
8 Sep 24 o Re: Am I missing something about (loop ... maximizing ...) ?1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal