Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You will live a long, healthy, happy life and make bags of money.


comp / comp.lang.lisp / Re: Loopy

SubjectAuthor
* LoopyB. Pym
+- Re: LoopyB. Pym
`* Re: LoopyB. Pym
 +- Re: LoopyB. Pym
 `- Re: LoopyB. Pym

1
Subject: Loopy
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sun, 9 Jun 2024 20:59 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Loopy
Date: Sun, 9 Jun 2024 20:59:10 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <v4552t$3poln$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sun, 09 Jun 2024 22:59:10 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3963e249935437964a8124639e46b0d8";
logging-data="3990199"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+5ISPdKScVaGJ36P45Zvze"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:VFuT+IeU0W32yoLUsYpQJGDWXZY=
View all headers

Kent M. Pitman wrote:

> The ability in loop to do even complex things like:
>
> (loop for x in '(1 2 3 4 5 6 7)
> when (evenp x)
> collect x into evens
> else
> collect x into odds
> finally
> (return (values evens odds)))
> => (2 4 6), (1 3 5 7)

Gauche Scheme

(partition odd? (iota 9)
===>
(1 3 5 7)
(0 2 4 6 8)

Subject: Re: Loopy
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sun, 9 Jun 2024 21:17 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Loopy
Date: Sun, 9 Jun 2024 21:17:05 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <v4564g$3q3qd$1@dont-email.me>
References: <v4552t$3poln$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sun, 09 Jun 2024 23:17:06 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3963e249935437964a8124639e46b0d8";
logging-data="4001613"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hWgepDDIkc/3YQb2Me1k2"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:NPGGAK7sYzEcs+fHGboCT3NL1Zs=
View all headers

On 6/9/2024, B. Pym wrote:

> Kent M. Pitman wrote:
>
> > The ability in loop to do even complex things like:
> >
> > (loop for x in '(1 2 3 4 5 6 7)
> > when (evenp x)
> > collect x into evens
> > else
> > collect x into odds
> > finally
> > (return (values evens odds)))
> > => (2 4 6), (1 3 5 7)
>
> Gauche Scheme
>
> (partition odd? (iota 9)
> ===>
> (1 3 5 7)
> (0 2 4 6 8)

> Also, being able to vary the collection is handy. Consider:
>
> (loop for x in '(a b (c d) e f)
> when (atom x)
> collect x
> else
> append x)
> => (A B C D E F)

Gauche Scheme

(append-map
(lambda(x) (if (pair? x) x (list x)))
'(a b (c d) e f))

===>
(a b c d e f)

Subject: Re: Loopy
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 10 Jun 2024 06:17 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Loopy
Date: Mon, 10 Jun 2024 06:17:09 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <v465p2$7ib2$1@dont-email.me>
References: <v4552t$3poln$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Mon, 10 Jun 2024 08:17:09 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="44bd2a413b5b1943ca0d6806e9035a8f";
logging-data="248162"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jhHWvqKftwZmxw1mfApoB"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:PKjSh5L1y1IlOfxbuNIkUGbTRRs=
View all headers

On 6/9/2024, B. Pym wrote:

> > The ability in loop to do even complex things like:
> >
> > (loop for x in '(1 2 3 4 5 6 7)
> > when (evenp x)
> > collect x into evens
> > else
> > collect x into odds
> > finally
> > (return (values evens odds)))
> > => (2 4 6), (1 3 5 7)

Peter Seibel wrote:

> (loop for x across array-of-numbers
> minimizing x into min
> maximizing x into max
> summing x into total
> counting t into count
> finally (return (list min max (/ total count))))

In Gauche Scheme, it's a one-liner.

(use gauche.sequence)

(define v #(0 2 -3 99 48 35 86 27 50 18))
(define count (vector-length v))

`(,(find-min v) ,(find-max v) ,(/ (fold + 0 v) count))
===>
(-3 99 181/5)

--

Subject: Re: Loopy
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 10 Jun 2024 07:56 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Loopy
Date: Mon, 10 Jun 2024 07:56:39 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <v46bjk$9erm$1@dont-email.me>
References: <v4552t$3poln$1@dont-email.me> <v465p2$7ib2$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Mon, 10 Jun 2024 09:56:39 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="44bd2a413b5b1943ca0d6806e9035a8f";
logging-data="310134"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UmqyWxC9sR9Kllz6PJy53"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:y3NyGrCHqKeeUZGVXONArGGznmg=
View all headers

On 6/10/2024, B. Pym wrote:

> On 6/9/2024, B. Pym wrote:
>
> > > The ability in loop to do even complex things like:
> > >
> > > (loop for x in '(1 2 3 4 5 6 7)
> > > when (evenp x)
> > > collect x into evens
> > > else
> > > collect x into odds
> > > finally
> > > (return (values evens odds)))
> > > => (2 4 6), (1 3 5 7)
>
> Peter Seibel wrote:
>
> > (loop for x across array-of-numbers
> > minimizing x into min
> > maximizing x into max
> > summing x into total
> > counting t into count
> > finally (return (list min max (/ total count))))
>
>

How about good old "do*"?

(defparameter v #(0 2 -3 99 48 35 86 27 50 18))
(defparameter len (length v))

(do* ((i 0 (1+ i))
(x (aref v i) (aref v i))
(mn x (min x mn))
(mx x (max x mx))
(sum x (+ sum x)))
((= (1+ i) len) (list mn mx (/ sum len))))

===>
(-3 99 181/5)

Subject: Re: Loopy
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Thu, 13 Jun 2024 03:13 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Loopy
Date: Thu, 13 Jun 2024 03:13:11 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <v4do46$22q3g$1@dont-email.me>
References: <v4552t$3poln$1@dont-email.me> <v465p2$7ib2$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Thu, 13 Jun 2024 05:13:11 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="1732be28450302a0a7b2cfd1fb42f3c5";
logging-data="2189424"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iAPQV/WtNTtO/mjHJTPc1"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:ks+KJcvKNs+BBd4XcGUzfTMyAaQ=
View all headers

On 6/10/2024, B. Pym wrote:

> Peter Seibel wrote:
>
> > (loop for x across array-of-numbers
> > minimizing x into min
> > maximizing x into max
> > summing x into total
> > counting t into count
> > finally (return (list min max (/ total count))))
>
>
> In Gauche Scheme, it's a one-liner.
>
> (use gauche.sequence)
>
> (define v #(0 2 -3 99 48 35 86 27 50 18))
> (define count (vector-length v))
>
>
> `(,(find-min v) ,(find-max v) ,(/ (fold + 0 v) count))
> ===>
> (-3 99 181/5)

Another way.

(define v #(0 2 -3 99 48 35 86 27 50 18))
(define count (vector-length v))

(let ((r (mul-vec-reduce (list + max min) v)))
(reverse (cons (/ (pop! r) count) r)))

===>
(-3 99 181/5)

Given:

(use srfi-43) ;; vector-fold

(define (mul-vec-reduce konses vec)
(let ((len (length konses)))
(vector-fold
(lambda (i accum x)
(if (null? accum)
(make-list len x)
(map
(lambda (f a b) (f a b))
konses
(make-list len x)
accum)))
'()
vec)))

1

rocksolid light 0.9.8
clearnet tor