Fork me on GitHub

Is it possible to get a repl while also running -main? For example I can do clj -m app.core and it starts my ring server, but no repl. If I only say clj then I get a repl but no server. Possibly related, how would I set up hot code reloading? Or even manually reload?


@coding.aaronp There are several options available to you. You can start a plain Socket REPL in any Clojure process by specifying a JVM option. You can connect to that via telnet or equivalent and some editors can connect to Socket REPL (most require nREPL, unfortunately).


You can programmatically start any type of REPL inside your -main function, including nREPL but you'll need the nREPL library as a dependency of your main program for that.


You could also start a REPL and then start the -main function from inside your REPL -- for most -main functions that will likely block you from interacting with the REPL (unless you start it asynchronously).


It's common practice to write your -main in such a way that it simply calls a few other functions, and provides a way to start those functions easily from the REPL instead.


See for example this comment form showing how to start/stop the web server in the REPL, just above the -main function


For what it's worth, at work we use the JVM option approach to start a Socket REPL in a lot of our processes -- even in production -- and then we can connect to those processes via telnet or our editor. We prefer that approach because it involves no extra code or dependencies in our production apps.


Now, on "hot code reloading" -- I just evaluate code into the REPL on every change. It's just a key chord (`ctrl-; B` in my case to eval the top-level form around the cursor). I don't even have to save the file to do that. Edit, eval, edit, eval, edit, eval... The REPL is always up to date that way. No need for anything to "watch" files and reload them in the background.


If you listen to talks and podcasts featuring Stu Halloway talking about his workflow, he also avoids anything like that -- he evals code into the REPL as he changes it. It's also what Eric Normand recommends in his (excellent) REPL-Driven Development source (on


Hmm very good food for thought, thanks


I always recommend trying to avoid "magic" in tooling and just learn an effective but simple workflow.


I've been using vim. I know the clojure plugin supposedly does that, but I haven't looked at it yet


Check out the #vim channel for help


Working with a REPL that is integrated into your editor is best. Never type directly into a REPL when you're actually developing code. It's okay to type directly into a REPL when you're just playing around, but working from your editor is the most productive way to work, once you've gotten used to it.


@dchristianbell That's not really a good topic for this channel. Perhaps have the discussion in #off-topic ?




+100 to all that Sean said. The closer you get to evaluating code directly from your editor, the faster you will go.


@nate Not sure why #vim didn't get highlighted as a link (made me wonder whether the channel had been archived)...


Yeah that was weird, maybe it's because I'm on iOS.


Fussy phone app? 🙂


I guess it doesn't highlight unless you pick it out of the list that pops up.


(ah, there we go)


If your editor/plugin of choice uses nrepl (like none of neovim/conjure), there's a bit of path fiddling done in dev to facilitate starting nrepl and a dev version of the app. Usually takes a bit to get set up, but then it's smooth like the socket repl.


Ok so... what do people think about cursive? Needless bloat, or does it get you closer to that ideal you just described?


I generally recommend people continue to use whatever editor they're already comfortable with


(as long as it has a Clojure integration)


Yes! Agreed.


1. The editor you already use 2. The editor your best clojure friend uses. 3. Emacs or vim.


"Beware the cult of Emacs" 🙂


(or the cult of vim)


Hahaha. Both!


No one ever gets to step three.


Haha yep. I've been loving neovim for ages, but always willing to expand my boundaries - if it's worth it


I've used TextMate, Sublime, Atom, LightTable, Emacs...


I gather Conjure is really good with neovim.


Conjure us the bees knees. Check out #conjure


(Hey, there it worked)


Oooooh that looks interesting


Thanks again!

👍 3

I really must give Neovim and Conjure a try. I occasionally do some vi/vim editing but I've never tried to do serious Clojure editing in it...


It was great to start, and then was rewritten to use fennel and is even better. Now it supports other lisps too.


(don't get me wrong: I love Atom + Chlorine and I have a lot invested in that in terms of integration with Cognitect's REBL so I'm not about to switch -- but it doesn't hurt to learn additional editors 🙂 )


I have a couple of videos up on YouTube showing how I work with Atom + Chlorine + REBL.


You've made me want to try out atom and chlorine with your videos. Also rebl.


One of these days...


I plan to do more screencasts soon 🙂

🍿 3
👍 3

@seancorfield What's your youtube channel? I want to subscribe. 🙂

☝️ 3

^ @chris358 LMK if that link works.


@dinbhardwaj As much as Emacs is far and away the most widely used for (serious) Clojure development, I really wouldn't recommend anyone trying to learn Emacs while they are also trying to learn Clojure.

Simon Prep11:07:06

Totally agree. I am not a stranger to Emacs and Lisp syntax to begin with. When I was trying to learn Clojure, first I thought it would be easy to skim over Java, Lein, REPL, Emacs, and cider-mode, .., and so on, superficially, I was wrong. The experience was so frustrating that I stopped learning it a couple times. So today, I start again with clj tool, on the usual "Hello World!" file. Well, I have accomplished a small, but concrete, step without sense of vagueness and uncertainty. So I agree with your comment. Don't get a newbie to learn Clojure on Emacs or Lein.


The usage of Emacs as a percentage is dropping each year I think as more people come into Clojure...


(and I used Emacs on and off for twenty years, so I'm not coming from an anti-Emacs place 🙂 )


Ten years ago, Emacs had 70%, and IntelliJ just 9%. vi had 18% and CIDER didn't exist.


Five years ago, Emacs/CIDER had ~45%, IntelliJ/Cursive had grown to about 27%. Vi was about 12%. LightTable and Sublime were next.

Cameron Kingsbury04:07:28

nice way to make {:a {:one 1 :two 2} :b {:three 3 :four 4}} => {:a/one 1 :a/two 2 :b/three 3 :b/four 4} ?

Cameron Kingsbury04:07:52

apart from just writing it myself


@U010Z6ZBHV4 `(reduce-kv (fn [m k v] (reduce-kv (fn [m' k' v'] (assoc m' (keyword (name k) (name k')) v')) m coll)` I think (see below)


But there's not going to be anything built-in.

Cameron Kingsbury04:07:46

okay thanks 🙂 didn't know if there was


Let me edit that to actually work: (reduce-kv (fn [m k v] (reduce-kv (fn [m' k' v'] (assoc m' (keyword (name k) (name k')) v')) m v)) {} coll)


user=> (def coll {:a {:one 1 :two  2} :b {:three 3 :four  4}})
user=> (reduce-kv (fn [m k v] (reduce-kv (fn [m' k' v'] (assoc m' (keyword (name k) (name k')) v')) m v)) {} coll)
{:a/one 1, :a/two 2, :b/three 3, :b/four 4}
(I actually tested it the second time!)


One thing to be aware of, that sort of transform leans into using namespace-qualification on keywords as a sort of structural semantics which I'd be very cautious of.


Qualified keywords are intended to identify entities that are unique across your domain, rather than imply any sort of nesting.

Cameron Kingsbury05:07:54

yea using it for fuzzy searches on nested maps

Cameron Kingsbury05:07:18

figured that would be a useful preprocessing step


And what about maps nested three or more levels deep? 🙂


If you combined them with . instead of trying to qualify them, you could handle arbitrarily-nested maps -- and then you wouldn't be "abusing" namespace qualification...


(keyword (str (name k) "." (name k'))) would do that.


VS Code / Calva is the fastest growing usage, up 10% from even last year!

Chris McCormick04:07:54

crazy prediction: in 10 years time the most common development environment for clojure will be browser based e.g. code-mirror + parinfer


I wonder... We've been promised cloud-based development as the norm for years...

Chris McCormick06:07:16

i guess my thesis is there will be a lot more people writing clojure, and a significant fraction of them will do so in the browser, because the browser will become the OS for many futurepeople. 10 years is probably optimistic. 😁


I wish I could argue against that but, given that several modern editors are basically "browsers" with the editor written in JS, I don't think I'd find my own arguments terribly convincing at this point...

Chris McCormick06:07:41

heheh yes electron has a lot to answer for!

Chris McCormick06:07:30

i actually mean the browser though. my 9 year old barely has a concept of the file system. nearly everything she does is in a browser tab. but yeah, definitely a wild prediction which has been made before and not come true!


We have the Chromebook as an example of what a browser O/S might look like -- but it still seems fairly niche to me. Of course, I'm ancient and still cling to a lot of seriously old-school practices! I think a good dev env should be able to run without an Internet connection of any sort (which is increasingly hard these days).

Chris McCormick06:07:45

i don't think internet connection == browser based

Chris McCormick06:07:22

agree it's niche right now


That's a fair distinction.

Chris McCormick06:07:48

i also cling to seriously old-school practices!


When I find myself using CodeMirror in REBL and it has paredit etc, I do sort of have a reality check and try to reconcile "browser" with "good editor experience" 🙂


Theia does a good job in making browser based editing as good as on the desktop.

😍 3

> my 9 year old barely has a concept of the file system even in the '80s / '90s most computer users had a minimal grasp on the file system


@seancorfield where did you get the data that emacs user are decreasing? I don’t believe the worlds best editor looses the shine. how it can loose member when more than 5000 package exists to meet your all needs at one place. Other editor are no competition. Even slack is on emacs now… … once in emacs, you never have to go outside to do anything. Mail reading, new reading, slack communicator and Org to do list … everything is there…. Everyone should be half Nerd/Hacker if he can’t be full one… And Emacs will help him out… Rest everything is individual choice as you had suggested.


I remember, back in the '90s, seeing HP demo an editor environment for C++ that was essentially all cloud-based (we didn't use "cloud" back then)


@dinbhardwaj I went back through the State of Clojure Survey results for the last ten years.


So it's a fact, despite your "religious fervor" for Emacs 🙂


(and we really discourage "editor wars" here -- just as we discourage "religion" and "politics" 👀 )


@chris358 Have you used any browser-based development environments?


Those developer surveys only show percentage of market share. Its not clear if emacs user count is decreasing or just more people are developing clojure and all user counts are increasing and more people are using all of the different editors. I'm hoping its a bigger pie 🙂

Chris McCormick05:07:42

@seancorfield i've built a couple of domain specific ones: and (the latter is for cljs editing)

Chris McCormick05:07:28

i'm planning to add eval'ed cljs support to slingcode but that is 100% vapourware at he moment


@dpsutton The number of respondents has gone from about 500 in 2010 to 2,500 in 2020 so you could argue that Emacs' numbers have grown (from 350 to 1075 roughly) except that we all know the survey respondents represent just a proportion of the community -- and, most likely, the most avid and engaged Clojure fans. That VS Code has grown by 10% in just the last year as Emacs' "market share" has declined slightly is indicative of a major shift in the community, I think the main takeaway is that we have more choices today and that a large portion of the community favors "other editors" -- which is a good thing: choice is important, and being able to onboard new Clojure developers using their current favorite editor is important.


totally agree with that.

Neil Ashton13:07:11

Agreed – I think the availability of #calva was a big reason my spark of curiosity about Clojure was able to explode as rapidly as it did (thanks @pez!).

❤️ 3
calva 3

Hi folks! Is there a best practice on how to use symbols from the same namespace on functions? I mean, I’ve been writing stuff like:

(def thing 1)
(defn a-fn
  (+ x thing))
But I have the feeling that this is wrong because of the “implicit” thing inside the function. Should I always pass it as an argument?


By “definition”, (def thing 1) defines what other languages would call a constant. As long as you use it that way, and don’t use any of the functions that would let you change thing to a different value, you’re probably ok.


I'm also a beginner, but I would think it depends on the situation. What you have there is a closure. You can call a-fn from another module and it works fine. But if you want thing to be more dynamic, depending on the module calling it, then pass it as an arg


The main idea is that your a-fn is “pure” (i.e. “good”) if it always gives the same result when given the same arguments.


Sometimes I’ll build something like this:

(def numstrings
  {1 "one"
   2 "two"
   3 "three"
   9 "nine"})

(defn as-string
  "convert a digit to a string"
  (get numstrings n))
By putting numstrings in a separate def, I’m keeping my function simpler and easier to read, and the value of numstrings isn’t going to change at runtime, so this is all good.

👍 3

the key is that calling def thing again later in your code should never happen


it might happen during development, of course, but not in application code

👍 3

Right, plus what’s the other one, alter-var-root or something?


You can tell I never use it 🙂


there are also dynamic vars which you can rebind temporarily using binding or with-bindings , but these have to be explicitly marked with the ^:dynamic metadata


What would be the best way to structure/add cljs to a clj project? I'm using the cli, got a ring server setup under src/clj/app Should I have src/cljs/... or make a whole new project? Something else?

Aviv Kotek14:07:43

hi, how would you remove backslash from a string, i have tried the following but no-success, (s/replace "<?xml version=\"1.0\"" #"\\" "") => "<?xml version=\"1.0\"" won't work also for "\\" OR \backslash Desired result: "<?xml version="1.0""


You may be running into a REPL gotcha there--your replace is probably working, but the REPL will put backslashes in front of embedded double-quotes


"<?xml version="1.0"" is not a valid string


or, its a string and then a double literal 1.0 and then an empty string


(str/replace "<?xml version=\"1.0\"" #"\\" "")
=> "<?xml version=\"1.0\""
(println (str/replace "<?xml version=\"1.0\"" #"\\" ""))
<?xml version="1.0"
=> nil


(println "<?xml version=\"1.0\"")
<?xml version="1.0"


you aren't replacing anything


That too 🙂


consider the string "bob \n marley". it does not contain a slash and an n. it contains a newline

👍 3

likewise, your string does not contain a slash and a quotation mark, it contains a quotation mark