Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

A triangle which has an angle of 135 degrees is called an obscene triangle.


devel / comp.lang.lisp / .Re: using loop macro to find argmax

SubjectAuthor
o .Re: using loop macro to find argmaxRobert L.

1
.Re: using loop macro to find argmax

<sv4d4f$122m$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!SZha8W+qDLGHmwO5lLKz2Q.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: using loop macro to find argmax
Date: Wed, 23 Feb 2022 04:28:00 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <sv4d4f$122m$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="34902"; posting-host="SZha8W+qDLGHmwO5lLKz2Q.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. - Wed, 23 Feb 2022 04:28 UTC

On Mon, 12 May 2003, Barry Margolin wrote:

> >Using the loop macro you can find the maximum of some numerical function
> >f, applied
> >to each element of a list by
> >(loop for x in list maxmimize (funcall f x))
> >
> >But I want to return the x such that (funcall f x) is maximum
> >and I would like to write something like this:
> >
> >(loop for x in list argmaximize (funcall f x))
> >
> >Is there some loop keyword that would do this?
> >If there isn't such a keyword what's the most succinct way to
> >do this with the loop macro?
>
> There isn't a keyword for it.
>
> (loop with max-val = (car list)
> for x in (cdr list)
> when (> (funcall f x) max-val)
> do (setq max-val x))

That doesn't function correctly.

Gauche Scheme:

(reduce
(lambda (a b) (if (> (square a) (square b)) a b))
'list-was-empty
'(2 -8 4 6))

===>
-8

That calls the function more times than necessary.

(define lst '(2 -8 4 6))

(fold
(lambda (a b)
(define res (square a))
(if (or (null? b) (> res (car b))) (list res a) b))
'()
lst)

===>
(64 -8)


devel / comp.lang.lisp / .Re: using loop macro to find argmax

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor