Fork me on GitHub
#clojure-uk
<
2017-10-10
>
thomas07:10:43

moin moin morning

guy07:10:25

morning!

yogidevbear09:10:44

Just want to check my understanding is correct here. This is an experiment to replicate the functionality of (count coll) as a learning exercise... (reduce (fn [result _] (inc result)) 0 [1 4.0 :foo "bar"]) In this example ☝️, reduce is in the form of (reduce f val coll) f is an anonymous function (`fn`) that is accepting two arguments. In the first iteration, reduce calls the anonymous fn and passes it 0 which is assigned to result, and the first element in the collection (`1` which is assigned to _ as we're not really concerned about storing this value). Then inc is applied to result which returns a value of 1 back to reduce. Then reduce takes this returned value of 1, passes it to the anonymous fn again as the result argument, and the next item in the collection (e.g. (first (rest coll))= 4.0) as _, repeats the inc call on result and returns 2 to the reduce function, etc, etc... until the 'coll' is exhausted and the final result of 4 is returned as the quantity of items in the initial coll (`[1 4.0 :foo "bar"]`)

yogidevbear09:10:05

I hope that actually makes sense when you read it 🙂

sundarj09:10:29

@yogidevbear that is correct 🙂

sundarj09:10:06

no worries

manas_marthi10:10:35

how to rewrite the above example using #( ) form?

bronsa10:10:52

it's not practical

bronsa11:10:15

you'd have to do something like #(do %2 (inc %)) which is eugh

bronsa11:10:33

because #() requires that all the args to the anon fn are used at least once in the body

bronsa11:10:43

(otherwise it wouldn't know how many args the fn needs to accept)

guy11:10:03

today i learned! Thanks for the tip

bronsa11:10:53

a little known fact of #() is that it also supports varargs via %&

bronsa11:10:39

or even.. %-1

bronsa11:10:45

(but that's a bug :P)

guy11:10:24

What does that last one do?

guy11:10:31

%-1 i mean

bronsa11:10:39

user=> (#(do %-1) 1 2 3)
(1 2 3)

bronsa11:10:08

you can even do

user=> (#(do %1.1234) 1)
1

guy11:10:17

oh i see

guy11:10:25

so thats just like calling %1 then?

bronsa11:10:49

yeah, it's a fun little missing validation in the parsing logic of the reader

dominicm11:10:47

oh, I didn't expect it to work like that. Having said that, how could it work any other way?

bronsa11:10:45

well the alternative would be to make all anon fns variadic and ignore the remaining args, but eugh

bronsa11:10:53

actually, what i said before is not entirely correct

bronsa11:10:07

#() doesn't require all the args to be used at least once

bronsa11:10:18

it just requires that the last argument to be used at least once

bronsa11:10:25

so #(%2) is valid

thomas11:10:16

What is the best way to debug a StackOverflow? I can see the stacktrace, but can't tell where it starts (The out put I get is all in clojure-1.8.0.ar code)

dominicm11:10:53

@bronsa yeah, I basically thought it did it variadically. But then I realised it must have to parse to figure out used variables in order to handle extra args. I mean cljs lets you do that I guess...

kevin4213:10:22

hello 🙂

danm14:10:08

What's the purpose of #clojure-uk specifically, as opposed to just #clojure?

danm14:10:04

I found out about it because a colleague was on here. I've been on the standard clojure/beginners etc channels for a while

dominicm14:10:32

it's "for" people in the UK, by name at least.

dominicm14:10:40

I think we're a bit more chatty than even #clojure though

dominicm14:10:59

I read way more of this channel at least

danm14:10:15

Eh, fair enough. I just wouldn't have figured we needed our own section over the base #clojure one. Still, I also idle in the IRC channel and that's got like 5-10 people in it who actually ever talk 😉

thomas14:10:08

@carr0t we do talk Clojure from time to time... but most other subjects are fine as well.

thomas14:10:08

the only "rule" we have is documented here: http://www.total-knowledge.com/~ilya/mips/ugt.html

iaint14:10:16

TIL about UGT. wish I'd come across that concept sooner :)

danm14:10:07

Time is an illusion

danm14:10:10

Lunchtime doubly so

dominicm15:10:18

Lunchtime is the only time I can count on

cddr22:10:40

Actually the time difference seems like a pragmatic reason to have this channel (or even a clojure-eu if we wanted to have our own little anti-brexit). We can be helping each other solve problems before the yankees[1] have had their coffee 😉 [1]: I say this as someone who married one so I mean no disrespect