Fork me on GitHub

Does anyone here use Ruby, Elixir, and Clojure? I’d be curious to see how Clojure compares (but not quite curious enough to knuckle down and learn Clojure quite yet)


What are curious about?




Hmm interesting. How do you find the ergonomics of reading/writing it? I saw that Rich Hickey is a fan of named params where position doesn’t matter, so I figured it must be in Clojure. Elixir doesn’t have that


Sure performance is a good one. Can you get microsecond response times from Clojure web servers? Erlang uses a fancy setup where it streams IO Lists to the TCP socket instead of concatenating strings. Saves on CPU and memory. Or maybe since Clojure is on the JVM, CPU performance is great enough to just chew through string concat.


I’m also curious about interop with JRuby, come to think of it 🙂


What else… what are the most common IDEs and editors? And what does deploy look like for a production web app? I haven’t done Java in many, many years.


@jon920 > What are the most common IDEs and editors? This post has a full list


I only have toy experience with Elixir and Ruby, while I do have professional Clojure experience, so take the following as you want. My favourite of the three is Clojure, followed by Elixir and then Ruby. That implies I like Clojure ergonomics the best, but I think they take a long time to get used too. REPL driven development is central to the ergonomics, and getting used to the Lisp syntax, infix notation, nested expressions. There's a lot more to get adjusted too before the ergonomics click


You probably meant prefix (Polish) notation.


Clojure does have positional args as well as named args, and anything in between. If you're curious, this post of mine: is a short read, and goes over very quickly the basic features of Clojure (well its ClojureScript in this case, but they're the same).


So that should give you a good idea of the basic ergonomics


For performance, I just wouldn't worry. Clojure is the fastest of the three. It will beat ruby and elixir at single and multi-threaded CPU performance, as well as can make use of shared memory.


Not sure what you mean related to the socket streaming. You can stream whatever you want over a socket.


JRuby interop is not something I tried. I did do Scala, Java and Kotin interop. Generally, to interop between these you basically put java in between, since they all interop with Java. So I'd assume JRuby would be the same.


Basically, if JRuby can make use of a Java class, well you'll be able to use Clojure from JRuby, since Clojure can expose itself through a Java Class or a Java object.


And similarly, if JRuby can expose itself as a Java class or object, Clojure will be able to make use of it through that.


Thanks that’s great info. What are a few of the most well-written clojure projects? In terms of code aesthetics and software architecture


Most of Clojure is written in Clojure, though implementing language constructs is definitely hairier. I heard people recommend cljdocs before, but I never checked its source personally:


Neat reading the core lib source. It’s surprisingly clear enough. Might have to dig into Clojure at some point here. I also wonder if we can get it on Graal VM alongside TruffleRuby


I'm not sure. Clojure doesn't have a Truffle based implementation. I'm not sure Truffle is appropriate either, since Clojure is compiled. But if Truffle based lang can interrop with Java, they should be able to interop with Clojure as well.


Most used ides/editors are probably: • Emacs • Idea with Cursive • Vim with Fireplace? • VsCode with Calva


I'd say so. Atom with Chlorine is popular as well.


• Neovim with Conjure


is it worth mentioning lightable? I found it super handy as a beginner


worth clarifying: lighttable is a clojure editor, written in clojure. So handy as an editor as a beginner, but also useful for reviewing well-written Clojure code (cc @jon920)


Nice :thumbsup:


But unfortunately it's a bit dead as of now.


oh really? thats a shame, i really liked it when i used it.


Last time I checked it was still using some deprecated Electron with multiple issues due to that and with no workforce to rewrite it.

👍 4

The LightTable code is great! Thank you.

Ike Mawira12:01:31

I would like help understanding why in the following code, the function 'custom-inc' never gets evaluated.

(defn custom-inc [pre]
  (if (nil? pre) 0 (inc pre)))
The workaround is choices is a string got from looping a seq with 'do-seq'
(send (agent {}) assoc choices custom-inc)
Returning the agent using '@' macro returns the values of the map as objects and not integers as intended. E.g
{"Android Development" #object[csv_parser.core$custom_inc 0x106c180 "csv_parser.core$custom_inc@106c180"],
 "Machine Learning and Artificial Intelligence" #object[csv_parser.core$custom_inc


looks like you may mean to use update instead of assoc?

Ike Mawira12:01:25

Ah, yes. Thanks. 😅


Does Clojure have an automatic code formatter tool? I’ve been using one with Elixir and it’s made onboarding a lot easier.


cljfmt and zprint would be the main ones. I use cljfmt personally. Simple and straightforward.


there's cljfmt, but that just does indentation and leaves line-breaks as is last I saw


clojure's formatting idioms (like any lisp) are much simpler than most languages


Interesting. I’m pretty sold on investing some time on Clojure but someone just threw me a curveball which is Scala. Obviously there are huge difference in syntax, and Scala also does OOP. But what other differences exist between the two? They seem to occupy a similar niche being FP languages on the JVM (from my complete newbie point of view)


aside from many other major differences in philosophy, scala is big on static typing while clojure is dynamic


I tried introducing Scala at work back in '09 but the long edit-compile-deploy-test cycle didn't sit well with folks here who had worked with dynamic languages, so we switched to Clojure.


Scala is a hybrid language so you can use it as just a "better Java" without leveraging the FP aspects. It's a very complex language too.


I'm not a fan of Scala


So I can't recommend it. Implicits are the worst language constructs I've ever seen


Scala has also suffered from a lot of backward compatibility problems over various releases, often forcing you to upgrade your entire toolchain just to use a newer version of the compiler (the 2.7 to 2.8 upgrade in particular was just horrendous!).


I'd sooner choose Kotlin as a "better Java" before I'd choose Scala.


Yup, I'll agree on implicits. They seem so, so convenient but they make code really hard to understand and reason about. So much "magic".


Yup, I'll agree on Kotlin too. I think it's a much nicer language than Scala. That said, I haven't used Kotlin in production (but I have used Scala).


Java is going to subsume all of those languages besides Clojure

❤️ 4

Oh no Scala has a long compile time? I can’t go back after seeing what is possible with Go.


I can see Kotlin thriving due to Android


lol. with regards to that. we chose java over scala for that reason. "oh java 10+ gives us all the stuff we want from scala anyway". but now we can only use java 8 because we need spark and spark is written in a version of scala that only supports java 8 and it's a massive project to rewrite of spark in a newer version of scala that supports a newer version of java so that we can write spark code in modern java 😆


I find Scala is a bit of a monster. It does OOP, it does FP, it tries to add extra typing to the JVM, the combination feels a bit chaotic. Like a jack of all trade, master of none.


I've heard second hand that with prudent use, Scala can be your ideal language, until you need to interact with someone else's Scala lib (and their ideal language is a different subset of Scala) - sounds a lot like the situation with C++


And Java interrop isn't very good as well


As someone who spent nearly a decade doing C++ (and was on the ANSI Standards committee for eight years), I don't think C++ even comes close to the complexity and multiple-dialects that Scala suffers from...

💡 4
🤯 4

one major benefit with Clojure is that interop works great both ways - it's designed to be simple to use Java libs from Clojure and to be simple to use Clojure libs from Java


And Clojure supports basic OOP concepts if you want them.. this shouldn't be OOP lang vs non-OOP lang


that's true, so long as you agree with me and other right thinking people that enheritance is not a core OOP feature :D


I don't even know what OOP is anymore


Most reasonable people avoid the original OOP concepts. OOP nowaways sounds like "this is OOP, therefore everything must live in a class, classes everywhere!"


Had a big convo with noisesmith about this just the other day 😛


I think of OOP as objects everywhere


A little meta: I think classes/objects by default is what people consider casually as "it supports OOP". ie mandatory classes = safe, OOP


I think we're saying the same things


I see an object as a self-referential collection of fields and methods. Like a data-structure that stores key/vals where vals can be values or functions. And where the functions inside the values have a magical implicit reference to the object, so it can refer to other keys in the object and make use of them.


Oh, a mutable data-structure as well.


And then OOP languages, are those who build upon this fundamental data structure


They don't have to have classes


Its actually quite a tricky structure. I think to make objects really concrete in your head, it helps to try and implement one. That self-referential property isn't obvious.


And it is what separates an object from a mutable Map


Anyways, that's only my chosen taxonomy. But I find it makes for a good model, and what I like about it, is from that angle, it makes sense that JS, Python, Java, are OOP, and that Clojure is not.

Alper Cugun19:01:39

I consider Scala an anti-pattern for many of the above mentioned reasons. I’ve seen several shops that programmed themselves in a corner when it comes to comprehensability, being able to hire etc.


How about Kotlin vs. Clojure? Not as a battle but a comparison of differences and trade-offs

Alper Cugun19:01:48

I’d add there that for instance Kotlin and Swift which look very much the same are already worlds apart. Swift has a lot stronger guarantees on immutability.

Zach Clark18:01:12

kotlin is java with less characters to type, if you want a new language but don't want to change anything about how you approach problems or write your code, it's safe

💯 8

I think it'll help you if I just described Clojure vs non-lisps 😛 Clojure is homoiconic, meaning that the same syntax is used to write code, as well as to represent data. Think of it like if all JavaScript code was valid JSON. This trait is unique to Clojure (and only a handful of other langs, mostly lisps). Since code is just data, it allows for very easy introspection facilities, and from that comes Macros. This enables a style of programming called Meta-Programming. That's the first thing that Clojure vs other-langs has. Clojure is a Meta-Programming language.


You will grow more as a programmer learning Clojure, but language choices rarely happen in isolation -- are you planning on tackling a problem, or just as a learning endeavor?


I’m looking to add another tool to my kit to invest in long term. Right now I have Go for CPU bound tasks and easy deploy. Ruby for general purpose. Erlang/Elixir for distributed and web performance. Javascript when forced to, or in the future when it gets pipelines and pattern matching. At this moment I’m actively working in Ruby, and spending a great deal of time learning Erlang/Elixir on the side. I’m already sold on keeping a close eye on Clojure for sure, just trying to get a grip on differentiators from sidelines without actually programming it yet.


The next one is the Lisp syntax. It uses infix notation, that's a big difference from other langs. (+ 1 2 3 4) instead of (1 + 2 + 3 + 4). Another thing with the syntax, it is very structural, and that allows for structural editing. You don't edit it using lines and spaces like other langs, instead you move up and down through it like if it was a Tree.


You mean "prefix notation", not infix.

🤤 4

Another big one is the REPL and the evaluation model. In Clojure, compile-time IS runtime. It doesn't even make sense to say compile-time. You need to think in terms of phases: read phase, compile phase, macro-expansion phase, evaluation phase. And all phases happen at runtime. It is a true dynamic language, not just in the sense of having dynamic types, but you don't go from source -> compiled form -> running form. You start with a running empty program, and as it is running, you add things to it, or modify existing things, or take things away. This is the foundation of the REPL driven development and is very different from other langs.


Now another difference, is even though it has all this dynamism, it is in fact, a compiled language, unlike most other dynamically type langs such as Python, Ruby, JS, etc.

Alper Cugun19:01:36

What does it compile to again?


JVM bytecode or JavaScript or .NET IR depending if you are using Clojure, ClojureScript or ClojureCLR

Alper Cugun19:01:21

Ah that way. So you have Clojure compiled or you have the same code interpreted in the REPL?


Clojure compilation happens at runtime. So the REPL compiles the code as it is being sent to the repl.


Clojure is never interpreted -- yeah, what he said.


The Clojure compiler works on a form-by-form basis, not a file, so the REPL and "running a program" work the exact same way.


That's why you can REPL into a live, running process -- even a production process -- and redefine functions on-the-fly, and it updates the bytecode (compiled, in-memory).

Alper Cugun20:01:04

The REPL also compiles to byte code every time you type something in?


Yes it does, like Sean said before, Clojure is never interpreted, always compiled.


@URK0TMXDG Stu Halloway talks about this in, I think, his REPL-Driven Development talk. He says we don't really need files etc since we could just feed our entire program to the Clojure REPL, one form at a time, in the right order, and it would have exactly the same semantics as Clojure "running" the program from the files.


If you type in (defn foo [n] (inc n)), it compiles immediately to a class named user$foo (assuming you're in a REPL in the user ns). You can see that by typing (class foo). If you type (ancestors (class foo)) you'll see all the interfaces implemented by that class and all the classes that are extended by it...

Alper Cugun11:01:41

And what does Clojurescript compile to then?


ClojureScript transpiles to JavaScript @URK0TMXDG (I don't use cljs so I can't provide more details than that).


You can use: too see what ClojureScript compiles too.


In the above case, (defn foo [n] (inc n)) becomes = (function cljs$user$foo(n){
  return (n + (1));


And in JavaScript, functions are already Objects. So in both cases, functions get compiled down to Objects of the underlying language.


Much as I'd like to consider JS to be the "assembly language of the web", the pedant in me has a hard time describing ClojureScript as a compiled language (hence my use of "transpiled") 🙂


Some people consider GCC a transpiler 😋


But in this case I just didn't want to confuse with semantic squabbles


(compilers, transpilers, and interpreters is what I used to do for a living back in the late 1980s which is why I'm a bit pedantic about it)


I think the official ClojureScript doc calls itself a compiler. And so does the Google Closure library and for example Babel. And all these things just output JavaScript. So I feel the line between compiler and transpiler has really blured and it seems more and more those are used interchangeably. Even Emscripten calls itself a compiler, but it actually compiles C/C++ into JavaScript! So its actually going from a lower level to a higher level language 😛


Crazy times we live in


Clojure is not interpretted


Also, it is an expression based language, it has no statements. That's a big difference too. It means that everything can be composed and nested one inside another.


And now I just covered the unique parts of Clojure related to it being a Lisp. But it is also a Functional first language with support for lazy and eager evaluation, with immutable data-structures, and support for full multi-threading and concurrent programming as well. It runs on more than one host platform: CLR, JVM, JS officially, with a few more unofficially: Erlang, C++, Go.


It also happens to have multiple-dispatch polymorphism (what made Julia famous), and traits based polymorphism, among others. And this is where I could go on an on, like the fact it also supports Logic programming, CSP, and others...


Are there libraries that support a BEAM style of lightweight VM processes and supervision trees? Being functional it seems possible.


Ya, meant prefix


@jon920 core.async adds lightweight processes, but there's no similar OTP for core.async. There's a few libraries that build on top tying to add their own best practice to it, but nothing super official or popular


Also, nothing quite like what the BEAM does, though I think Pulsar/Quasar are tying to add that to the JVM, dunno


core.async is more like go than erlang


(unamed processes communicating via queues that are values, vs named processes communicating via implicit queues)


Its kinda getting into the details of what we mean exactly by "lightweight process", but generally, people mean less resource heavy than an OS thread, and core.async fits that bill. But if someone means something more akin to Actors, where processes have state and communicate with each other only through messages, and that there is a GC per process, etc. ya Clojure doesn't have that as far as I know, except for Clojerl off course 😛, the Clojure dialect running on BEAM


There's a rational behind it as well:


Rich Hickey doesn't like the downside of actors, that when they don't help, they make things slower and more complicated. And that they don't actually extend from local to network magically as advertised.


The Language of the System - Rich Hickey


I need to re-watch that one, don't remember the content!


Maybe January 2020 I'll have myself a little Rich Hickey maraton 😛


basically what you just said


just linked it as a reference for drilling down


Hope he has a new talk this year haha, I need my Rich Hickey fix


If you prefer reading to listening/watching, and want a few extra references/links thrown in for good measure, there are transcripts of most of his talks here:


Are there any other languages that blow your mind like Clojure, and are also robust and production ready? I’m eyeing ML languages like Haskell (but haven’t dove in because I hear it compiles slow), and maybe a Prolog like from some of these new databases I’ve seen.


Rust might be interesting here - some ML influence, good for systems work


@jon920 Mind-blowing languages: definitely Prolog, definitely Haskell, maybe Elm, Rust, APL...


I think Dotty is a great thing. They recently announced feature completeness of the new compiler.


Dotty = new compiler for Scala


also, Ocaml is an ML that compiles very quickly if that's the main concern (it generates fast code too)


Multiprocessing story of Ocaml is quite weak though.


I see F# as more practical ML implementation. Even syntactically is less bizarre.


(maybe F# -- also in the ML family -- but for its Typed Providers stuff?)


I’m avoiding Rust because it compiles slow, I’m guessing because the language is so complex. Trying to avoid waiting on compilers in the next decade of my life.


Rust make you ❤️ garbage collector 🙂


C even more so 🙂


Some people talk nicely about Nim


The thing is that Rust has a claim that unlike Haskell, I believe in. Trade some convenience for the borrow checker, and you get memory safety without overhead.


When this is what you need, it is pretty awesome


Haaskell says, trade some convenience for pedantic static type checking and have less bugs, but I don't believe it truly reduces bugs, so I don't find that trade to be a good one. Rust on the other hand makes a trade that I can see taking.


I tell you what the problem is here. I was talking to Phil Wadler when he was in Prague. I asked him what he thinks about linear types. That's what Rust is based around. And he replied that "it's not worth it". Of course this is argument by authority and maybe he would even dismissed my quotation as it is written here. But I actually have feeling it's huge and inconvenient trade off.


Some even simple things are unnecessary complex with Rust. And their Result type is leaky because of unwrap etc.


But I'm not expert at all. I wish Rust shiny future, because it is quite modern compiler. It would be nice if it succeeds!


That's fair. I mean, for many things, a GC is just better. But when you need something more performant, that's when I feel it could be worth it. Also, Rust types are affine, slightly more convenient to use then linear types. Some people might argue that, something like C++ unique_ptr is enough, so you lean on move semantics only when needed, instead of Rust's default to move semantics. We'll see, every new release of Rust they make it slightly more ergonomic. Lets see how far they can take it.


My personal fav is hardware accelerated GC. I hope this becomes standard in the future. I saw some paper on it, and they achieve such better performance, almost eliminate completely the GC overhead.

👍 4
Zach Clark19:01:58

I think I've tried to pick up Rust once every year for the past few years, the complexity is ridiculous, the language is optimized for maximum cognitive overhead


My other languages of current interests are Rust and Red. I'd say Prolog, J, Racket, WebPPL and Forth are all mind blowing as well.


+1 for Forth as mind-blowing.


Well, I should mention Carp, which is a Clojure-like Rust 😛


Such a shame this never took off

🤯 4

(for a while, we actually used Gershwin instead of Clojure and had some stack-based code... but switched back to pure Clojure as it diverged from the version used in Gershwin)

Kamuela19:01:47 is there a digits function as the question author mentions? Or is he neglecting that he wrote it himself?


there's no digits function, IIRC this is one of the puzzles from


looks like the question was edited to include the digits function


@U051SS2EU thanks for pointing that out, totally missed that


@seancorfield: I'm using clj-new to scaffold a new app, and when I'm trying to run the uberjar, I get an error. Here's how I got it:

$ clj -A:new app a-b-c/Fixed-DHCP
$ cd Fixed-DHCP
$ clojure -A:uberjar
Compiling a-b-c.Fixed-DHCP ...
Building uber jar: Fixed-DHCP.jar
Processing pom.xml for {a-b-c/Fixed-DHCP {:mvn/version "0.1.0-SNAPSHOT"}}
$ java -jar Fixed-DHCP.jar
Error: Could not find or load main class a-b-c.Fixed-DHCP


I suspect the issue is with converting - to _, but I'm not sure where that _ needs to be replaced


Yeah, right now depstar doesn't do that translation. I'll create an issue to address that...

❤️ 4

much better in 0.5.1


And clj-new updated to 0.8.4 to include the fixed depstar too!

❤️ 4

Thanks for spotting that!


is a macro the right way to turn:

{:end-point "abc"}
(-> (builder)
    (.endPoint "abc")


there's some java interop builder stuff I'm trying to work with, but I'm tired of writing (.something ,,,) over and over and I'd rather just use data


there's definitely prior art to doing things this way


got any links?


I mean, for that specific case, a function should do


@U0K064KQV I think the intention here is that the :foo-bar keyword be translated to a .fooBar setter method


@U0FEHF1RS I looked but didn't see it in the place I expected


Oh I see, like an auto-mapper thingy


the camel-snake-kebab library does the kind of key - method name translation you'd want at least


then it's just a question of doing that parsing / translation to build the final form (you might want eval too here...)


I have no experience in writing macros. Can you explain why an eval is needed?


macros can only operate on literal data in a source form, in order to construct method calls out of keywords that are not literals (eg. if they come from some var or data somewhere else), you need eval (as new method calls can't be created at runtime without expensive and complex reflection)

👍 4

macros are functions that take values at compile time and turn them in to other values, that are then fed in to the compiler


the problem with using macros for that kind of thing is it limits you to dealing with data that is static and known at compile time


the only reason people reach for macros for that kind of thing is because they are scared of using reflection


ok -- so, what's the reflection-y way to do this ☝️


I'd have to check whether org.clojure/ supports builders... I know it supports setters...


something like

(defn f [m]
  (let [b builder]
    (doseq [[k v] m]
       (clojure-to-java-name (name k))
    (.build b)))
you'll need to write or find a clojure-to-java-name


Is there a nice, simple builder in the standard Java library I can try it out on?


you could also write a function that creates the form you want and just call eval on it


Well, that has setters so I know that will work.


(-> (new java.util.Locale$Builder)
    (.setLanguage "en")


I have a working version of in git that supports this:

{:git/url ""
 :sha "20d8562bf451f41bf58ac0b38401648ba21232a3"}
in deps.edn and then
(require '[ :as builder])
(builder/to-java java.util.Locale {:language "en"})


@seancorfield: how would I call (builder/to-java ,,, if my builder is actually initialized like this: (ABC/builder) instead of (new ABC$Builder) ?


I get this error: > Error: > Execution error (InstantiationException) at sun.reflect.InstantiationExceptionConstructorAccessorImpl/newInstance (


A static method on the parent class?


Thanks. Yeah, I'm going to need to support building on an instance in cases where I can't just construct the builder class... gimme a few...


OK, the latest version on GitHub supports (builder/to-java ABC (ABC/builder) props opts) so you can pass in a builder instance if it can't be directly constructed from a class.

👏 4

Ah, actually, no. expects the original object to be mutable and the setters to return void. So it doesn't work. Hmm...


Might be a nice enhancement to support that...


(the doseq in the above will need replacing with reduce then)