Deutsch   English   Français   Italiano  
<m3a5ih1gss.fsf@leonis4.robolove.meer.net>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Madhu <enometh@meer.net>
Newsgroups: comp.lang.lisp
Subject: Re: How do i get multiple Min() values?
Date: Tue, 16 Jul 2024 21:15:55 +0530
Organization: Motzarella
Lines: 60
Message-ID: <m3a5ih1gss.fsf@leonis4.robolove.meer.net>
References: <v6qu7m$2vg8q$1@dont-email.me> <v6rug7$35c6s$2@dont-email.me>
	<20240715051340.619@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Tue, 16 Jul 2024 17:45:43 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="603ad98f9877f7a58ead02fbcf0c5817";
	logging-data="1406628"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+xfRWN2HBYo0U//SpWuH5no2cqqGzc4pA="
Cancel-Lock: sha1:qCLPCsAeO4Ol95MYhNVGBFq05TY=
	sha1:VGM5YM8Gy1HZq6N5iDWUOr5jQNU=
Bytes: 2887


* Kaz Kylheku <20240715051340.619@kylheku.com> :
Wrote on Mon, 15 Jul 2024 12:27:58 -0000 (UTC):

> On 2024-07-12, HenHanna <HenHanna@devnull.tb> wrote:
>>>
>>> How do i get multiple Min() values?

You just need the count of the min value.  you don't really need
"multiple min() values". right?

>>> e.g. for   Y = (x-2)*(x-3)   for x in range(-10,10)
>>> the min Y is hit twice
>>>
>>> print(  min( ((x-2)*(x-3),  (x, (x-2, x-3)))
>>> for x in range(-10,10) ) )
>>>
>>> is this easy in Scheme(Gauche) ?

>> if the   Min()   is going to check all of the Candidate values,
>>      it could (at least) tell us  how many times the Min value was seen!
>
> I decided to add something like this to TXR Lisp.
>
> It will appear in 296.
>
> This is the TXR Lisp interactive listener of TXR 295.
> Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
> When transferring between containers, do not siphon TXR by mouth.
> 1> (find-mins -10..11 : [callf * pppred ppred])
> (2 3)
> 2> (find-mins (vec-seq -10..11) : [callf * pppred ppred])
> #(2 3)
> 3> (find-mins "abracadabra")
> "aaaaa"
> 4> (find-maxes "abracacabra")
> "rr"
>
> I works with any less-like function, assuming equality
> when it's neither true that x is less than y, nor that
> y is less than x.

Ugh. One would think it is be trivial in CL to track the min-count as a
wrapper around (reduce #'min list)

but the REDUCE spec makes it hairy to get edge cases right (where the
input is an empty list or singleton list).

(defun hen-min (list &aux (min-count 1))
  "LIST is a list of numbers. Return the MIN of the list. Second
return value is the count of the MIN in the given LIST"
  (values (reduce (lambda (&optional a b)
		    (when a
		      (prog1 (min a b)
			(cond ((< b a) (setq min-count 1))
			      ((= b a) (incf min-count))))))
		  list)
	  (if (endp list) 0  min-count)))

It still reads nicer without any [???]