Fork me on GitHub
#adventofcode
<
2019-02-13
>
potetm01:02:56

@chase-lambert reductions terminates when (reduced acc) gets returned.

potetm01:02:42

1) mapv is not lazy. It returns a vector immediately. map is lazy.

potetm01:02:17

I mean, lazy evaluation is not something you should have to consider constantly, but you do need to know about it.

potetm01:02:42

The biggest gotcha is probably with side effects. For example, (map print [1 2 3]) — works in the REPL, won’t work in the middle of a fn.

potetm01:02:28

2) (Integer. "123") and (Integer/parseInt "123") do exactly the same thing. You can confirm this in the Java source code.

potetm01:02:16

I prefer Integer/parseInt & Long/parseLong because I find it to be more explicit.

potetm01:02:42

I also default to longs instead of ints because that’s what clojure does.

potetm01:02:56

3) Thank you!

potetm01:02:40

4) I understood the logic 🙂 I thought about skipping it entirely, but it’s good to know that you can use existing clojure fns as a starting point for what you need to do.

potetm02:02:21

fwiw - duplicates gets used quite a bit. I even introduced it into my professional code base not long ago and have used it multiple times there.

potetm02:02:36

The code might have been difficult to follow, but the abstraction is solid.

potetm02:02:53

5) Yeah cursive inserts the ns require for me. I really don’t know anything about Cider.

potetm02:02:49

You must require namespaces before you use them. You got lucky because clojure.string is brought in by clojure.main.

potetm02:02:02

This is kind of a gotcha at the REPL, because things like clojure.pprint get required on REPL startup but not on clojure.main.

potetm02:02:56

Best practice is to put all of your requirements in your ns declaration.

potetm02:02:11

5.b) Yeah the bottom right is a REPL buffer. I don’t use it very often, but it can be nice for small one-off forms.

potetm02:02:27

I’m glad you found it helpful! I’m more than happy to continue answering questions here. My only other thought would be reddit so people could search it via google later. Feel free to post a link/links and have discussion there if you like.

ghadi16:02:56

fyi (Integer. "123") is deprecated

ghadi16:02:11

per the Java API

ghadi16:02:24

Integer/parseInt is the sauce

bananadance 5
dpsutton16:02:24

@Deprecated(since="9") apparently the docs from java 7 are the top result. thanks!

Chase16:02:06

This was all great information folks, thank you! Integer. is out. parse... is my new best friend

Chase17:02:23

I also like that defaulting to Long/parseLong because it's the clojure default. I think I found that Integer. method on an old stackoverflow answer

dpsutton17:02:39

what is the clojure default?

Chase17:02:47

potetm mentioned above that he uses Integer/parseInt and Long/parseLong but between those two he would choose parseLong by default since that is what clojure uses.

dpsutton17:02:31

oh the default integer type for clojure. gotcha 👍. ( I was confused by what you meant by clojure default)

Chase17:02:05

if you really grilled me, I would be confused by what I'm saying too. hahaha

Chase17:02:44

ok, you got me. What is the actual difference between a Long and an Int in clojure?

Chase17:02:36

from what I can gather, Longs can be much larger?

dpsutton17:02:50

Longs are 64 bits and therefore in memory are much larger. The increased width can handle a larger range of values

dpsutton17:02:13

longs are what the reader returns unless an even bigger size is required.

Chase17:02:22

cool. I'm still in the newbie wonderment phase trying to grasp just how fast computers run all these damn calculations. It spits out the answer for that part2 problem we were discussing immediately. so fast.

gklijs17:02:38

There was someone solving ALL solutions in some milliseconds if I remember correctly, in C

Chase17:02:30

I saw that! The entire advent in less than a second. I've seen it in C++ and Rust. crazy stuff.