Fork me on GitHub
#beginners
<
2017-02-09
>
rauh15:02:05

@eslachance Your let doesn't wrap the lower case

eslachance15:02:28

So I can't do a let within a case?

rauh15:02:58

No, look again, the let doesn't do anythign right now

rauh15:02:18

It's on the same indentation level as the case

eslachance15:02:19

It should be running d/transact!

rauh15:02:47

Put the cursor on the opening parenthesis of the let and see where the closing paren is

eslachance15:02:03

At the end of the line that says d/transact!

eslachance15:02:09

Which is where I expect it to be

sveri15:02:16

Also cursive shows that "packet" and "map-name" are unused local variables

rauh15:02:34

You need to put the cursor on the let and slurp

eslachance15:02:53

so this is "if the type is presence_update, define newpacket and use it"

eslachance15:02:07

"if the packet is this_other_one, define another var and use it"

rauh15:02:16

This is what you have:

(let [a 0])
(foo a)

rauh15:02:30

You need:

(let [a 0]
  (foo a))

eslachance15:02:41

no... it's... correct.

eslachance15:02:55

you can see ] at the end of the second-to-last line

rauh15:02:02

THE FIRST LET! 🙂

rauh15:02:26

No worries, 😉

eslachance15:02:33

Yep! That was me being blind, I added the let after making the case 😄

eslachance15:02:43

This whole thing is so ridiculous and it's because this API sends packets that have too many inconsistencies. Bit frustrating

rubek19:02:37

I’ve got a very weird problem doing one of the 4clojure exercises, hope some of you fine folks can help me

rubek19:02:43

(It’s the one where I got to return the intersection of two sets without actually using intersection)

rubek19:02:09

Filter, clojure.set/select and contains? seem to work just fine when I call them individually, i.e. (clojure.set/select #(= 0 %) #{0 1 2}) returns #{0} as expected.

rubek19:02:09

And (contains? #{1 2 3} 0) returns false and (contains? #{1 2 3} 1) gives me true, which is all fine.

rubek19:02:00

But when I try to use the contains? method as a predicate, it seems to just always return true

rubek19:02:56

i.e., the function (fn [s1 s2] clojure.set/select #(contains? s2 %) s1) I wrote which I thought should do the trick simply returns s1

rubek19:02:58

I find this a very weird behaviour, given the individual components seem to do exactly what I expect them to do. There’s gotta be something trivial I’m missing here, but I cannot find it

donaldball19:02:54

If your function is actually just as written, it will always return s1

donaldball19:02:40

The function body consists of a sequence of three forms. The first two evaluate to function values, and the last is the return value.

rubek19:02:02

Oh wait… I missed a parenthesis didn’t I

donaldball19:02:19

probably 🙂

rubek19:02:45

Aaaah 😅

rubek19:02:44

Okay so it just thinks I give it a bunch of functions for fun without doing anything with it

rubek19:02:53

Thank you! Oh my

donaldball19:02:29

np, this is one of those areas where, when coming from another language, one might be used to getting a syntax error, but clojure doesn’t care

rubek19:02:57

Exactly… many languages have the last as return value, but only clojure gets me confused in what I actually use in a call. Thank you so much!

eslachance22:02:37

Ok so... earlier today I almost had to eat my socks because I was having a discussion with people in Discord about programming languages (started by someone claiming "nodejs was more efficient that java because paypal uses it"). Now, I was talking about how Clojure is super awesome at math and was laughing at javascript for claiming that 0.1+0.2 == 0.3 was false... so I ran (+ 0.1 0.2) in the REPL expecting to show them a screenshot and to my greatest surprise... lo and behold the result is actually 0.30000000000000004 . So I have to ask... What, Why?

dominicm23:02:08

@eslachance look into why doubles suck for precision. Java has BigDecimals to allow for precision when you want it.

eslachance23:02:38

Oh for a moment there I thought you were adding millions together

dominicm23:02:31

Nope, it's a slightly confusing syntax, I know . There's also 1N for big integer.

dominicm23:02:44

@eslachance of course, js doesn't even have the option to do all this. JVM owns node.js in performance on anything remotely CPU intensive. Also worth noting that clojure can get better performance than node.js does with IO through things like manifold. Not forgetting that we can allocate buffers in the kernel for 0-copy network transfers (so fast!). And of course, we can do all this in many threads, not just one.

dominicm23:02:26

Just look at Netty for a high performing web server with excellent reviews.

eslachance23:02:04

Well I won the argument on the sole basis that running 100,000,000 iterations of a recursive fibonnaci function of 50 depth was consistently 10x faster in clojure than in was in javascript

eslachance23:02:15

21 seconds versus 2.0 seconds

dominicm23:02:05

No doubt you could make it even faster with a type annotation too...

eslachance23:02:21

And I've seen how aleph.http can be blazing fast to retrieve from an API over http get. It didn't even seem like it was doing any HTTP stuff so fast it was

dominicm23:02:33

Node js is good at IO. I think JVM might be better.

eslachance23:02:11

I'm building a library to create bots for Discord, and I've already gotten a couple of people interested in "upgrading" from node to Clojure

eslachance23:02:25

Dithcord will be a stepping stone.

dominicm23:02:03

@eslachance aleph is netty. I believe that this is the secret behind the speed: The kernel allocates the network card the buffer to read into. Then the kernel gives us a pointer at that buffer, and allows us to read it. No copying! Traditionally you'd have a few copies from buffer to buffer.

eslachance23:02:17

Also I'm using DataScript for temporary storage of data which is amazing too

eslachance23:02:27

All these tools are great.