adventofcode

Happy Advent 2020! Please put answers in the pinned threads or create one if it does not exist yet. | https://github.com/adventofcode-clojurians/adventofcode-clojurians | Join the private leaderboard with code 217019-4a55b8eb
2019-02-13T01:49:56.026600Z

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

2019-02-13T01:50:42.027100Z

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

2019-02-13T01:51:17.027600Z

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

2019-02-13T01:53:42.029300Z

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.

2019-02-13T01:55:28.030100Z

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

2019-02-13T01:56:16.031Z

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

2019-02-13T01:56:42.031500Z

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

2019-02-13T01:57:56.031800Z

3) Thank you!

2019-02-13T01:58:40.032700Z

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.

2019-02-13T02:00:21.033900Z

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.

2019-02-13T02:00:36.034300Z

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

2019-02-13T02:02:53.035200Z

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

2019-02-13T02:05:49.036300Z

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

2019-02-13T02:07:02.037300Z

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

2019-02-13T02:07:56.038Z

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

2019-02-13T02:09:11.039100Z

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.

2019-02-13T02:14:27.040900Z

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.

ghadi 2019-02-13T16:39:56.041300Z

fyi (Integer. "123") is deprecated

ghadi 2019-02-13T16:40:11.041700Z

per the Java API

ghadi 2019-02-13T16:40:24.042Z

Integer/parseInt is the sauce

1
dpsutton 2019-02-13T16:50:24.042500Z

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

Chase 2019-02-13T16:58:06.043800Z

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

Chase 2019-02-13T17:02:23.044700Z

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

dpsutton 2019-02-13T17:04:39.044900Z

what is the clojure default?

ghadi 2019-02-13T17:05:17.045200Z

long

Chase 2019-02-13T17:06:47.046300Z

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.

dpsutton 2019-02-13T17:07:31.047500Z

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

Chase 2019-02-13T17:09:05.048Z

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

Chase 2019-02-13T17:11:44.048900Z

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

Chase 2019-02-13T17:12:36.049200Z

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

dpsutton 2019-02-13T17:13:50.049800Z

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

dpsutton 2019-02-13T17:14:13.050300Z

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

Chase 2019-02-13T17:35:22.051600Z

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.

gklijs 2019-02-13T17:37:38.051700Z

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

Chase 2019-02-13T17:38:30.051900Z

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