Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Never reveal your best argument.


comp / comp.lang.lisp / Re: Can you help me get rid of the setf?

SubjectAuthor
o Re: Can you help me get rid of the setf?B. Pym

1
Subject: Re: Can you help me get rid of the setf?
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Tue, 27 Aug 2024 07:19 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: Can you help me get rid of the setf?
Date: Tue, 27 Aug 2024 07:19:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <vajumn$2t35i$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Tue, 27 Aug 2024 09:19:53 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d78ccab14f3242b110cd9f2ce3d0e77f";
logging-data="3050674"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+j841pAC+mw/TRC2FGiEvC"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:ZbZMmNkxelQ59kLnkT5xIGLpQg0=
View all headers

> Frank Buss <fb@frank-buss.de> writes:
> > Looks like you are searching for a functional way of doing this. In Haskell
> > you could write it like this (I'm a Haskell newbie, I'm sure this can be
> > written better, but at least it works)
> >
> > f (x,y) = 9*x + 4*y - x*x - y*y
> > best = foldr1 max values
> > where values = [(f(x,y), (x,y)) | x<-[0..9], y<-[0..9]]
> > max t1 t2 = if (fst t1) >= (fst t2) then t1 else t2
>
> let f x y = 9*x+4*y-x*x-y*y in
> foldl1' max [(f x y,(x,y)) | x <- [0..9], y<-[0..9]]
>
> is a little simpler. Uses the max built-in and foldl1' which operates
> left to right and is strict.

Gauche Scheme

(use gauche.collection)
(use util.combinations)

(let1 f (^(x y) (+ (* 9 x) (* 4 y) (* x (- x)) (* y (- y))))
(find-max
(map (^x (list (apply f x) x))
(cartesian-product (list (iota 10) (iota 10))))
:key car))

(24 (5 2))

1

rocksolid light 0.9.8
clearnet tor