Fork me on GitHub
Michael Fiano01:10:21

I'm having trouble adjusting to Clojure coming from CL. "Brave" seemed to go too fast for me. I need to get used to the basics, preferably with writing code instead of a reference textbook. Any recommendations?

Michael Fiano01:10:22

I'm moreso looking for something better suited for someone with many years of Lisp experience, just not Clojure or the JVM


Joy of Clojure isn't an easy book, but it does start from a lisp oriented background


(also I think it's one of the better programming books)

Michael Fiano01:10:52

I was told that's a good reference book to have next to you, but not a linear read to get the language down.

Michael Fiano01:10:12

I haven't read it yet though


I'd say it's got plenty of linear introduction


joy of clojure and Ï really liked living clojure as well. I’ve purchased just about every book related to clojure to see what worked best.


One of the biggest changes from idiomatic CL code is the default immutability of data structures, and the easy access and very common use of maps, vectors, and sets. Lists are there, but the others are probably used more often than lists.

Michael Fiano01:10:28

I just started reading Clojure Applied, and I think it's too big of a step for me so far

Michael Fiano01:10:42

I'll try Joy since it keeps on being recommended. Thanks for the suggestions


I wonder what the best intro is for JVM via interop with Clojure. I basically learned Java by learning Clojure (at least the parts of Java you need in order to use the JVM interop...)


I basically did the opposite with ClojureScript, learning JavaScript via interop. :)


I also learned js via cljs interop, mostly


but I don't know cljs/js as well as I know clj/jvm at this point


@mfiano What other Clojure books have you (tried to) read, and what did you think of them?

Michael Fiano01:10:23

@seancorfield Clojure For The Brave and True only. I thought it was too quirky and moved a little too fast for me to really get. I've never done any parallel programming before, and there was a bit of this IIRC, and also I just couldn't get into the immutable mindset, coming from CL.


Can you article where you're struggling with the JVM aspects of Clojure, compared to the Lisp aspects?


Hmm, have you looked at Living Clojure by Carin Meier?


I agree that Brave is kinda quirky and not to everyone's taste but Carin's book is supposed to be a pretty gentle way in...

Michael Fiano01:10:51

I haven't yet, but it's what I'm going to try next I think.


Russ Olsen's Getting Clojure might also be an option (although I get mixed messages about whether it's truly an intro book or not).

Michael Fiano01:10:45

Also hello again sean. I'm back to studying Clojure after a 6 month hiatus, and I remember you helped me a bit, which I found really nice. Thanks


I'm happy to try to help 1:1 with the JVM aspects if you think I can assist...?

Michael Fiano01:10:57

I don't really know anything about the JVM, or when I would come across it in Clojure

Michael Fiano01:10:03

So I haven't yet 🙂


Well, I'm on West Coast US time so feel free to DM me with questions when I'm around 🙂

Michael Fiano01:10:22

Thank you, I'll keep that in mind. 🙂

Michael Fiano01:10:31

For now I'll read Carin's book


I have a copy of that so I can try to help with questions about that too 🙂


(I think I've got a copy of almost every Clojure book 🙂 )

Michael Fiano01:10:28

I discovered the incident with zcaudate. Looks like I'll have to modify my global lein profile to remove his stuff.

Michael Fiano02:10:37

Hmm I get a bunch of warnings when starting a lein REPL

Michael Fiano02:10:54

A lot has changed since I tried Clojure it seems


Clojure hasn't changed much in the last 6 months. If you have updated to a later JVM version, you may be hitting some teething pains due to updates in the JVM since then.

Michael Fiano02:10:04

Yeah I downgraded from 10 to 8, and most warnings went away...only have this now: WARNING: boolean? already refers to: #'clojure.core/boolean? in namespace: fipp.visit, being replaced by: #'fipp.visit/boolean?


Feel free to share the warnings/errors and we'll offer direction if we can...


Ah, going from Clojure 1.8 to 1.9? That introduces a lot of new predicates to support clojure.spec -- you may well need to update all the various library dependencies as well.

Michael Fiano02:10:03

cider doesn't support jdk10. that was all the warnings

Michael Fiano02:10:27

except that last one left


You should be able to ignore that -- I expect fipp.visit/boolean? is effectively the same functionality as Clojure 1.9's cloure.core/boolean?


Looks like that warning has been addressed in a more recent version of fipp


It was fixed almost a year ago.


Like I say, if you're going from Clojure 1.8 to 1.9, you'll probably have to update a lot of library versions as well to avoid warnings (and potentially "syntax" errors detected by clojure.spec that used to be silently allowed by the compiler).

Michael Fiano02:10:30

How doI tell what fipp is a transitive dependency of?


lein deps :tree should show you

Michael Fiano02:10:25

Oh I missed it


It may be a dependency of one of your plugins... oh, ok.

Michael Fiano03:10:51

It's from spyscope, which I don't even remember what that does, so I can probably remove it


You can exclude the old version of fipp (`bigml/fipp`) from spyscope and specify a newer version [fipp "0.6.13"]


[spyscope "0.1.6" :exclusions [bigml/fipp]] [fipp "0.6.13"]] should fix that I think...


(looks like Brandon changed the name of the artifact...?)


Or maybe spyscope was using an old fork?

Michael Fiano03:10:37

It looks like spyscope 0.1.7 is a fork that is 1 commit ahead and 10 commits behind the original 0.1.6 repository


(it does seem that people run into problems with old dependencies that they add to ~/.lein/profiles.clj -- back when I used Leiningen, I found it was safer to avoid putting things in that file!)


(and that fork has a very out of date readme -- still refers to 0.1.5 release 😞 )

Michael Fiano03:10:10

I just removed it from my deps


v basic question that i’m having trouble googling successfully: what does Integer. mean? and/or what’s the difference between (Integer. "42") and (Integer/parseInt "42")?

Alex Miller (Clojure team)04:10:09

both create an instance of an Integer object

Alex Miller (Clojure team)04:10:26

the first uses the constructor (the trailing dot on the class is interop form to invoke the constructor)

Alex Miller (Clojure team)04:10:12

the second invokes a static method Integer/parseInt, which is now the preferred way to do this - Integer has a static cache for values around 0 and has been intrinsified for performance in later jdks

Alex Miller (Clojure team)04:10:21

the primary perceivable difference is the val cache:

Alex Miller (Clojure team)04:10:23

user=> (identical? (Integer. "42") (Integer. "42"))
user=> (identical? (Integer/parseInt "42") (Integer/parseInt "42"))

Alex Miller (Clojure team)04:10:51

the latter is definitely preferred


okay cool thanks


and is the reason neither works as a function is that both are technically objects?


in the context of (def formatters {:name clojure.string/lower-case :number Integer/parseInt}) for example


(which throws an error unless it’s wrapped like #(Integer/parseInt %)


(Integer. "42") is a call to a Java constructor. (Integer/parseInt "42") is a call to a Java method. Neither of those by themselves are Clojure functions, but they can be made into Clojure functions in several ways, one of which is the #(Integer/parseInt %) syntax you mentioned.


Or more precisely worded, you can create a Clojure function that way, that does nothing but call a Java method. Doing so does not change the Java method in any way -- it is still a Java method.


that’s really clear, thanks for the clarification!


just for my own edumucation, is there a “better” way of wrapping a Java method into a clojure function than my attempt?

Alex Miller (Clojure team)12:10:01

There’s also although that often leads to reflective calls


The way you showed is quite common and readable, and no less efficient than any of the other ways that I know of. One other is just a slightly more verbose way that does exactly the same thing under the covers: (fn [x] (Integer/parseInt x)). Another is to use Clojure's memfn.


awesome. thanks!

peter-kehl12:10:45 sounds out of date. It reads: > Symbols begin with a non-numeric character and can contain alphanumeric characters and *, +, !, -, _, ', and ? (other characters may be allowed eventually). However, lower than < and greater than > work, too. Can you see any other characters that are not listed?

Alex Miller (Clojure team)12:10:15

This section is intentionally ambiguous. It provides guidance on what is definitely allowed.

Alex Miller (Clojure team)12:10:45

And in some cases what is definitely not allowed

Alex Miller (Clojure team)12:10:18

While attempting to leave the door open on other characters to future mods


Is there any function in clojure which returns the first n natural numbers? Similar to F# way of using let a = [1..100];;



user=> (range 10)
(0 1 2 3 4 5 6 7 8 9)

👍 8

why not (circle 42)?

Andrea Imparato19:10:34

hello everyone, I’m about to buy the Getting Clojure book because I’ve read that is highly recommended for beginners like me

Andrea Imparato19:10:48

can anybody confirm me this? 🙂


I read it as a non-beginner and it indeed has a very gradual ramp up to the syntax and important concepts.


But I was already familiar with the material so can’t comment further.

Andrea Imparato19:10:48

ok, what about Clojure Applied? I already read Clojure for the brave and trueactually

Andrea Imparato19:10:12

so I’m already aware of the language syntax and structures

Andrea Imparato19:10:35

what I’m missing is more how to build real world applications and how to think in the “functional way”


@andrea.imparato I really enjoyed Clojure Applied. Seems like it could be what you are looking for. The back of the book says "[...]Discover how to use Clojure in the real world[..]". For me the chapters "Model Your Domain", "State, Identity and Change", "Use Your Cores" and "Thinking in Clojure" was some of the topics that I found extra interesting having already read some other Clojure books ("Clojure for the brave and true" one of them). I haven't read Getting Clojure so I cant compare the two.


If you already know Clojure’s syntax definitely get Clojure Applied.


Actually, I’m not which book out there gives you “the functional way”. It might be one of those things that you have to practice than read out of a book.


I highly recommend doing some toy problems like Advent of Code that will force you to write some algorithms with immutable data structures.

Andrea Imparato21:10:45

thanks for your answers guys :)


The moment you realize you can’t use a mutable variable followed by a for loop, forcing you to think in terms of filter/map/reduce, that was a huge first step for me. Not in Clojure, in my case, but in Elixir, but same principles.


@andrea.imparato thinking about it perhaps "Functional programming patterns in Scala and Clojure" could be of interest?

Andrea Imparato21:10:16

@rpkn yeah that could be good too by looking at the summary 👍


@orestis Would you say Joy of Clojure might be a good one for "the functional way"? (I had an FP background before I read it so I'm not sure I'm a good judge -- but that would be the book I'd consider recommending) /cc @andrea.imparato


I can’t remember whether I’ve read that or not...


So I have a macro that throws an exception when some of its arguments are invalid and I am failing to test for that with clojure.test/thrown?, it doesn’t catch the exception. Is it possible to catch exceptions from macros?


only if the try/catch surrounds the initial compilation of the form


remember that macros run when creating the bytecode for your form, not when that bytecode gets executed


so (is (thrown? ...) (eval '(my-macro ...)))