notzmv has quit [Remote host closed the connection]
<elcaro>
what is the idiomatic way to sum hash values
<elcaro>
i know i can do (for/sum ([(k v) (in-hash h)]) (+ v))
<elcaro>
but wondering if there's a better way
ZombieChicken has quit [Quit: WeeChat 2.5]
ZombieChicken has joined #racket
Sgeo_ has joined #racket
notzmv has joined #racket
Sgeo has joined #racket
Sgeo has quit [Read error: Connection reset by peer]
Sgeo__ has quit [Ping timeout: 245 seconds]
Sgeo_ has quit [Ping timeout: 258 seconds]
Sgeo has joined #racket
pera has joined #racket
<clacke_movim>
(for/sum ([v (hash-values h)]) v)
ricekrispie2 has joined #racket
ricekrispie has quit [Ping timeout: 245 seconds]
jao has quit [Ping timeout: 268 seconds]
<bremner>
clacke_movim: btw, are you clack@ something on mastodon?
<clacke_movim>
clacke@libranet.de
<bremner>
cool.
<clacke_movim>
That's me
<clacke_movim>
Also a bunch of other clacke, notclacke and reposterclacke, but that's my main.
dddddd has quit [Remote host closed the connection]
libertyprime has quit [Read error: Connection reset by peer]
orivej has joined #racket
ubLIX has quit [Quit: ubLIX]
cantstanya has quit [Remote host closed the connection]
cantstanya has joined #racket
libertyprime has joined #racket
notzmv has quit [Ping timeout: 258 seconds]
lavaflow has joined #racket
lavaflow_ has quit [Read error: Connection reset by peer]
notzmv has joined #racket
cromyr_ has quit [Ping timeout: 248 seconds]
_whitelogger has joined #racket
GoldRin has joined #racket
zmv has joined #racket
pera has quit [Ping timeout: 245 seconds]
endformationage has quit [Ping timeout: 248 seconds]
sauvin has joined #racket
simendsjo has joined #racket
_whitelogger has joined #racket
iyzsong has quit [Ping timeout: 248 seconds]
simendsjo has quit [Ping timeout: 248 seconds]
dustyweb has quit [*.net *.split]
bremner has quit [*.net *.split]
jcowan has quit [*.net *.split]
evdubs_ has quit [*.net *.split]
jackhill has quit [*.net *.split]
badkins has quit [*.net *.split]
thallada has quit [*.net *.split]
iclon__ has quit [*.net *.split]
moldybits has quit [*.net *.split]
dmiles has quit [*.net *.split]
gko has quit [*.net *.split]
soegaard has joined #racket
dustyweb has joined #racket
bremner has joined #racket
jcowan has joined #racket
evdubs_ has joined #racket
jackhill has joined #racket
badkins has joined #racket
dmiles has joined #racket
iclon__ has joined #racket
thallada has joined #racket
moldybits has joined #racket
gko has joined #racket
zipper has joined #racket
miskatonic has joined #racket
Sgeo_ has joined #racket
Sgeo has quit [Ping timeout: 248 seconds]
miskatonic has quit [Quit: ERC (IRC client for Emacs 24.5.1)]
orivej has quit [Ping timeout: 248 seconds]
soegaard has quit [Quit: soegaard]
zipper has quit [Ping timeout: 244 seconds]
zipper has joined #racket
iclon_ has joined #racket
ym has joined #racket
iclon__ has quit [Ping timeout: 248 seconds]
soegaard has joined #racket
pellertson has quit [Remote host closed the connection]
soegaard has quit [Quit: soegaard]
erkin has quit [Quit: Ouch! Got SIGIRL, dying...]
erkin has joined #racket
Sgeo__ has joined #racket
erkin has quit [Quit: Ouch! Got SIGIRL, dying...]
erkin has joined #racket
Sgeo_ has quit [Ping timeout: 245 seconds]
Urfin has joined #racket
Sgeo__ has quit [Read error: Connection reset by peer]
Sgeo__ has joined #racket
zipper has quit [Quit: WeeChat 2.5]
GoldRin has quit [Remote host closed the connection]
Sgeo_ has joined #racket
cromyr__3 has joined #racket
Sgeo__ has quit [Ping timeout: 245 seconds]
dddddd has joined #racket
Fernando-Basso has joined #racket
refpga has joined #racket
ZombieChicken has quit [Quit: WeeChat 2.5]
_whitelogger has joined #racket
rubic88 has joined #racket
soegaard has joined #racket
iyzsong has joined #racket
orivej has joined #racket
rubic88 has quit [Remote host closed the connection]
jao has joined #racket
_whitelogger has joined #racket
refpga has quit [Read error: Connection timed out]
refpga has joined #racket
ubLIX has joined #racket
tilpner has quit [Quit: WeeChat 2.4]
tilpner has joined #racket
refpga has quit [Ping timeout: 245 seconds]
refpga has joined #racket
<greghendershott>
clacke_movim: elcaro: Using `in-hash-values` with `for` can be faster (than using `hash-values`).
<greghendershott>
Another option, if you don't want to use `for` and don't mind producing an intermediate list, is `(apply + (hash-values h))`.
<clacke_movim>
greghendershott: ah! Thanks.
<clacke_movim>
(the in-hash-values info)
<clacke_movim>
Apply + was my immediate thought, but that would work well only for short lists of values.
<clacke_movim>
I hope for/sum is able to compile to something neat if the length of the list is known?
<clacke_movim>
Does it run + on some empirically chosen n number of operands at a time?
<soegaard>
clacke_movim: for/sum uses + on two arguments at a time
<soegaard>
In an (apply + terms) the standard + will also loop through the arguments and the current element to a tally using binary addition.
<clacke_movim>
Ok
Fernando-Basso has quit [Remote host closed the connection]
refpga has quit [Ping timeout: 268 seconds]
refpga has joined #racket
endformationage has joined #racket
iyzsong has quit [Ping timeout: 248 seconds]
pera has joined #racket
iclon__ has joined #racket
Arcaelyx has joined #racket
iclon_ has quit [Ping timeout: 258 seconds]
<ermo>
bremner: thanks for tips and pointers ^^'
refpga has quit [Read error: Connection reset by peer]
refpga has joined #racket
<winny>
(time (apply + (range 100))) => 4950 (time (foldl + 0 (range 100))) => 4950 ; so they are roughly equivalent in this case?
casaca has quit [Ping timeout: 272 seconds]
YuGiOhJCJ has quit [Quit: YuGiOhJCJ]
casaca has joined #racket
<soegaard>
winny: What does (define xs (range 100)) (time apply + xs) (time (foldl + 0 xs)) give ?
casaca has quit [Ping timeout: 245 seconds]
rubic88 has joined #racket
casaca has joined #racket
casaca has quit [Ping timeout: 268 seconds]
casaca has joined #racket
efm has joined #racket
casaca has quit [Ping timeout: 258 seconds]
casaca has joined #racket
casaca has quit [Ping timeout: 258 seconds]
casaca has joined #racket
ubLIX has quit [Quit: ubLIX]
refpga has quit [Read error: Connection reset by peer]
refpga has joined #racket
dimitarvp has joined #racket
casaca has quit [Ping timeout: 248 seconds]
casaca has joined #racket
<winny>
oh silly me, I wrote the wrong part of the output. Interestingly the foldl takes longer? cpu: 0, real: 0, gc:0 for (apply + xs) and cpu: 0, real: 1, gc: 0 for (foldl + 0 xs)
<soegaard>
Results that small drown in noise.
<soegaard>
Try a substantial longer list.
<soegaard>
Like 10000 or 100000.
casaca has quit [Ping timeout: 248 seconds]
casaca has joined #racket
jao has quit [Ping timeout: 272 seconds]
vraid has joined #racket
cantstanya has quit [Remote host closed the connection]
cantstanya has joined #racket
casaca has quit [Ping timeout: 246 seconds]
casaca has joined #racket
casaca has quit [Ping timeout: 245 seconds]
casaca has joined #racket
dimitarvp has quit [Quit: Bye]
casaca has quit [Ping timeout: 245 seconds]
casaca has joined #racket
casaca has quit [Ping timeout: 258 seconds]
casaca has joined #racket
FreeFull_ has joined #racket
FreeFull has quit [Ping timeout: 245 seconds]
FreeFull_ is now known as FreeFull
casaca has quit [Ping timeout: 272 seconds]
casaca has joined #racket
acarrico has joined #racket
orivej has quit [Ping timeout: 244 seconds]
casaca has quit [Ping timeout: 268 seconds]
casaca has joined #racket
miskatonic has joined #racket
casaca has quit [Ping timeout: 245 seconds]
casaca has joined #racket
Sgeo_ has quit [Ping timeout: 245 seconds]
miskatonic has quit [Quit: ERC (IRC client for Emacs 24.5.1)]
jao has joined #racket
casaca has quit [Ping timeout: 272 seconds]
casaca has joined #racket
jao has quit [Remote host closed the connection]
jao has joined #racket
ricekrispie has joined #racket
ricekrispie2 has quit [Ping timeout: 245 seconds]
acarrico has quit [Ping timeout: 258 seconds]
mSSM has joined #racket
soegaard has quit [Quit: soegaard]
rubic88 has quit [Remote host closed the connection]
notzmv has quit [Ping timeout: 246 seconds]
zmv has quit [Read error: Connection reset by peer]