Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Condense soup, not books!


comp / comp.lang.scheme / Re: Am I missing something about (loop ... maximizing ...) ?

SubjectAuthor
o Re: Am I missing something about (loop ... maximizing ...) ?B. Pym

1
Subject: Re: Am I missing something about (loop ... maximizing ...) ?
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Sun, 8 Sep 2024 07:03 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: Am I missing something about (loop ... maximizing ...) ?
Date: Sun, 8 Sep 2024 07:03:27 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <vbji7r$1rikb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sun, 08 Sep 2024 09:03:27 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="de24915e676d9d6eb68db0c7521c53ca";
logging-data="1952395"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/THqGOa6G7lUbSHnJIEbAD"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:5uefp6/8SgU285p1+lDf7pLgZCA=
View all headers

> 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)

1

rocksolid light 0.9.8
clearnet tor