Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Thufir's a Harkonnen now.


devel / comp.lang.lisp / Re: accumulating in vectors?

SubjectAuthor
* accumulating in vectors?James Cloos
+- Re: accumulating in vectors?Robert L.
+- Re: accumulating in vectors?Spiros Bousbouras
`* Re: accumulating in vectors?Tom Russ
 `- Re: accumulating in vectors?Madhu

1
accumulating in vectors?

<m3fsoi3fbq.fsf@carbon.jhcloos.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: cloos@jhcloos.com (James Cloos)
Newsgroups: comp.lang.lisp
Subject: accumulating in vectors?
Date: Wed, 16 Feb 2022 12:13:13 -0500
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <m3fsoi3fbq.fsf@carbon.jhcloos.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="88153ccf2f2f7e31794acdfbdf8cf690";
logging-data="31419"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+aDDjBiDy85qgKYsNBb0Nv"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
Cancel-Lock: sha1:Dz/4ArUWtP68+tZPJ+pGKmlWA28=
sha1:H649QNHFGUTLpX3vU9v+eit657w=
Face: iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAgMAAABinRfyAAAACVBMVEX///8ZGXBQKKnCrDQ3
AAAAJElEQVQImWNgQAAXzwQg4SKASgAlXIEEiwsSIYBEcLaAtMEAADJnB+kKcKioAAAAAElFTkSu
QmCC
Copyright: Copyright 2022 James Cloos
OpenPGP-Fingerprint: E9E9 F828 61A4 6EA9 0F2B 63E7 997A 9F17 ED7D AEA6
OpenPGP: 0x997A9F17ED7DAEA6; url=https://jhcloos.com/public_key/0x997A9F17ED7DAEA6.asc
 by: James Cloos - Wed, 16 Feb 2022 17:13 UTC

Is there a more efficient and/or idiomatic way in cl to do this:

(defun cumul (vctr)
(loop for j from 1 to (1- (length vctr))
do (setf (aref vctr j) (+ (aref vctr j) (aref vctr (1- j)))))
vctr
)

-JimC
--
James Cloos <cloos@jhcloos.com> OpenPGP: 0x997A9F17ED7DAEA6

Re: accumulating in vectors?

<sukbib$bt0$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!oLbwv41N8DscUwPT6F1sxQ.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: Re: accumulating in vectors?
Date: Thu, 17 Feb 2022 02:23:08 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <sukbib$bt0$1@gioia.aioe.org>
References: <m3fsoi3fbq.fsf@carbon.jhcloos.org>
Injection-Info: gioia.aioe.org; logging-data="12192"; posting-host="oLbwv41N8DscUwPT6F1sxQ.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. - Thu, 17 Feb 2022 02:23 UTC

On 2/16/2022, James Cloos wrote:

> Is there a more efficient and/or idiomatic way in cl to do this:
>
> (defun cumul (vctr)
> (loop for j from 1 to (1- (length vctr))
> do (setf (aref vctr j) (+ (aref vctr j) (aref vctr (1- j)))))
> vctr
> )

Gauche Scheme:

(define (cumul vec)
(vector-map-with-index!
(lambda (i el)
(if (zero? i)
el
(+ el (vector-ref vec (- i 1)))))
vec))

(define v (vector 2 3 4 5))
(cumul v)
v ===>
#(2 5 9 14)

Re: accumulating in vectors?

<oQmtgOHP0uVLyulWO@bongo-ra.co>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.lisp
Subject: Re: accumulating in vectors?
Date: Thu, 17 Feb 2022 12:23:17 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <oQmtgOHP0uVLyulWO@bongo-ra.co>
References: <m3fsoi3fbq.fsf@carbon.jhcloos.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 17 Feb 2022 12:23:17 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d15bc0604173a459718f2328ad5e1426";
logging-data="8882"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1862ui6SJuV9WnBQDjvpfQV"
Cancel-Lock: sha1:c5UqFfP5OH/xyLpUXSha0tPD/h0=
In-Reply-To: <m3fsoi3fbq.fsf@carbon.jhcloos.org>
X-Organisation: Weyland-Yutani
X-Server-Commands: nowebcancel
 by: Spiros Bousbouras - Thu, 17 Feb 2022 12:23 UTC

On Wed, 16 Feb 2022 12:13:13 -0500
James Cloos <cloos@jhcloos.com> wrote:
> Is there a more efficient and/or idiomatic way in cl to do this:
>
> (defun cumul (vctr)
> (loop for j from 1 to (1- (length vctr))
> do (setf (aref vctr j) (+ (aref vctr j) (aref vctr (1- j)))))
> vctr
> )

I wouldn't say more idomatic but it is a bit shorter to write

(defun cumul2 (vctr)
(loop for j from 1 to (1- (length vctr))
do (incf (aref vctr j) (aref vctr (1- j))))
vctr)

; it saves you writing (aref vctr j) twice.

Any of the following 2 versions *may* be faster :

(defun cumul3 (vctr &aux (sum 0) (pos 0))
(map nil (lambda (el) (setf sum (+ sum el)
(aref vctr pos) sum pos (1+ pos)))
vctr)
vctr)

(defun cumul4 (vctr)
(do ((sum 0) (len (length vctr)) (pos 0 (1+ pos)))
((eql pos len) vctr)
(setf sum (+ sum (aref vctr pos)) (aref vctr pos) sum)))

--
To solve this problem, we define a security flag, known as the "evil"
bit, in the IPv4 [RFC791] header. Benign packets have this bit set to
0; those that are used for an attack will have the bit set to 1.
RFC 3514

Re: accumulating in vectors?

<8f99f230-f0de-4373-a1ba-ec1074cda596n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:a05:600c:1d99:b0:37b:b813:c7aa with SMTP id p25-20020a05600c1d9900b0037bb813c7aamr7500889wms.108.1645125420081;
Thu, 17 Feb 2022 11:17:00 -0800 (PST)
X-Received: by 2002:aca:42c6:0:b0:2cc:a020:c00f with SMTP id
p189-20020aca42c6000000b002cca020c00fmr1746133oia.86.1645125418872; Thu, 17
Feb 2022 11:16:58 -0800 (PST)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!pasdenom.info!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.128.88.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Thu, 17 Feb 2022 11:16:58 -0800 (PST)
In-Reply-To: <m3fsoi3fbq.fsf@carbon.jhcloos.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:8000:7603:1703:c8fe:7a0:e6bc:de59;
posting-account=05zmAwoAAAAJZM-3jv1hCWLHGZQceqwA
NNTP-Posting-Host: 2603:8000:7603:1703:c8fe:7a0:e6bc:de59
References: <m3fsoi3fbq.fsf@carbon.jhcloos.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8f99f230-f0de-4373-a1ba-ec1074cda596n@googlegroups.com>
Subject: Re: accumulating in vectors?
From: taruss@google.com (Tom Russ)
Injection-Date: Thu, 17 Feb 2022 19:17:00 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Tom Russ - Thu, 17 Feb 2022 19:16 UTC

On Wednesday, February 16, 2022 at 9:13:21 AM UTC-8, James Cloos wrote:
> Is there a more efficient and/or idiomatic way in cl to do this:
>
> (defun cumul (vctr)
> (loop for j from 1 to (1- (length vctr))
> do (setf (aref vctr j) (+ (aref vctr j) (aref vctr (1- j)))))
> vctr
> )

Not necessarily quite as clear, but this does get to use MAP-INTO:

(let ((last 0))
(map-into *v* #'(lambda (x) (setq last (+ x last))) *v*))

Re: accumulating in vectors?

<m35ypcd6w4.fsf@leonis4.robolove.meer.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: accumulating in vectors?
Date: Fri, 18 Feb 2022 11:59:47 +0530
Organization: Motzarella
Lines: 28
Message-ID: <m35ypcd6w4.fsf@leonis4.robolove.meer.net>
References: <m3fsoi3fbq.fsf@carbon.jhcloos.org>
<8f99f230-f0de-4373-a1ba-ec1074cda596n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="f63f71d38dcaab5308bea37921abfe90";
logging-data="18852"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19H0gcxoO2w3JMRxdGBynSNTR+ZAcqyt2E="
Cancel-Lock: sha1:K68IBrredVJ53MWY9kHm9H76NeY=
sha1:53oocPhk4u5NZhv+Gqk14+Znw+4=
 by: Madhu - Fri, 18 Feb 2022 06:29 UTC

* Tom Russ <8f99f230-f0de-4373-a1ba-ec1074cda596n @googlegroups.com> :
Wrote on Thu, 17 Feb 2022 11:16:58 -0800 (PST):

> On Wednesday, February 16, 2022 at 9:13:21 AM UTC-8, James Cloos wrote:
>> Is there a more efficient and/or idiomatic way in cl to do this:
>>
>> (defun cumul (vctr)
>> (loop for j from 1 to (1- (length vctr))
>> do (setf (aref vctr j) (+ (aref vctr j) (aref vctr (1- j)))))
>> vctr
>> )
>
> Not necessarily quite as clear, but this does get to use MAP-INTO:
>
> (let ((last 0))
> (map-into *v* #'(lambda (x) (setq last (+ x last))) *v*))

the way to do cumul while keeping a running sum is just (reduce '+ list)

or (reduce (lambda (a b) (+ a b)) list)

but it loses the elegance when you have to mutate an array as a side effect

(let ((i -1))
(reduce (lambda (a b) (setf (aref v (incf i)) (+ a b)))
v
:initial-value 0))


devel / comp.lang.lisp / Re: accumulating in vectors?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor