Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Almost nothing in Perl serves a single purpose. -- Larry Wall in <199712040054.QAA13811@wall.org>


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

SubjectAuthor
o .Re: Am I missing something about (loop ... maximizing ...) ?Robert L.

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

<t0m1h7$1anf$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16958&group=comp.lang.lisp#16958

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!zmNK1LYt0c+WQ5+Oram9Yw.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: Am I missing something about (loop ... maximizing ...) ?
Date: Mon, 14 Mar 2022 00:16:44 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t0m1h7$1anf$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="43759"; posting-host="zmNK1LYt0c+WQ5+Oram9Yw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: XanaNews/1.18.1.6
X-Notice: Filtered by postfilter v. 0.9.2
 by: Robert L. - Mon, 14 Mar 2022 00:16 UTC

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

Gauche Scheme:

Shorter by more than 100 characters.

(define (find-maximizing-item items :optional (key values))
(define (triple-it item i) (list item (key item) i))
(define (max-it item i triple)
(let ((candidate (triple-it item i)))
(if (or (not triple)
(> (cadr candidate) (cadr triple)))
candidate triple)))
(apply values
(fold
max-it
#f
items
(lrange 0))))

(find-maximizing-item (list "one" "two" "three" "fifteen" "four"
"five") string-length)

===>
"fifteen"
7 3


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

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor