@chase-lambert reductions
terminates when (reduced acc)
gets returned.
1) mapv
is not lazy. It returns a vector immediately. map
is lazy.
I mean, lazy evaluation is not something you should have to consider constantly, but you do need to know about it.
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.
2) (Integer. "123")
and (Integer/parseInt "123")
do exactly the same thing. You can confirm this in the Java source code.
I prefer Integer/parseInt
& Long/parseLong
because I find it to be more explicit.
I also default to longs instead of ints because that’s what clojure does.
3) Thank you!
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.
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.
The code might have been difficult to follow, but the abstraction is solid.
5) Yeah cursive inserts the ns require for me. I really don’t know anything about Cider.
You must require namespaces before you use them. You got lucky because clojure.string
is brought in by clojure.main
.
This is kind of a gotcha at the REPL, because things like clojure.pprint
get required on REPL startup but not on clojure.main
.
Best practice is to put all of your requirements in your ns declaration.
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.
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.
fyi (Integer. "123")
is deprecated
per the Java API
Integer/parseInt is the sauce
@Deprecated(since="9")
apparently the docs from java 7 are the top result. thanks!
This was all great information folks, thank you! Integer.
is out. parse...
is my new best friend
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
what is the clojure default?
long
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.
oh the default integer type for clojure. gotcha 👍. ( I was confused by what you meant by clojure default)
if you really grilled me, I would be confused by what I'm saying too. hahaha
ok, you got me. What is the actual difference between a Long and an Int in clojure?
from what I can gather, Longs can be much larger?
Longs are 64 bits and therefore in memory are much larger. The increased width can handle a larger range of values
longs are what the reader returns unless an even bigger size is required.
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.
There was someone solving ALL
solutions in some milliseconds if I remember correctly, in C
I saw that! The entire advent in less than a second. I've seen it in C++ and Rust. crazy stuff.