Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You are taking yourself far too seriously.


comp / comp.lang.lisp / Re: finding the min or max element of a list

SubjectAuthor
o Re: finding the min or max element of a listB. Pym

1
Subject: Re: finding the min or max element of a list
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Thu, 18 Jul 2024 08:27 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
Subject: Re: finding the min or max element of a list
Date: Thu, 18 Jul 2024 08:27:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <v7ajkm$2b52a$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Thu, 18 Jul 2024 10:27:07 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8e507d2f4c44ea84c4d5df38107e66f0";
logging-data="2462794"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/uyB1KK5TyECkuvahXo+Iw"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:LsHw86FrRH9+wZc0KfseyozvB30=
View all headers

> (defun best (lst cmp &key (key #'identity))
> (loop with rtn = (car lst)
> for x in (cdr lst)
> when (funcall cmp (funcall key x) (funcall key rtn))
> do (setq rtn x)
> finally (return rtn)))

Gauche Scheme

(define (best lst cmp :key (key identity))
(reduce
(lambda (x chosen)
(if (cmp (key x) (key chosen))
x chosen))
#f
lst))

(best '((a) (f o o b) (b a r) (2 3)) > :key length)
===>
(f o o b)

(best '(5 0 4 9) >)
===>
9

(best '() >)
===>
#f

(best '(2) >)
===>
2

1

rocksolid light 0.9.8
clearnet tor