Re: Can you help me get rid of the setf?

Liste des GroupesRevenir à cl scheme 
Sujet : Re: Can you help me get rid of the setf?
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.scheme
Date : 27. Aug 2024, 09:19:53
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vajumn$2t35i$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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))

Date Sujet#  Auteur
27 Aug 24 o Re: Can you help me get rid of the setf?1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal