Fork me on GitHub

is there a clojure built in that does the equivalent of this?

(defn do-to [thing fun]
          ;; if map apply fun to all vals
          (map? thing)
          (zipmap (keys thing)
                   #(fun %)
                   (vals thing))
          ;; if list, apply fun to each else
          (coll? thing)
              (map fun thing)
              ;; if a singular thing, apply fun to it
              :else (fun thing)


no there is nothing like this in core. I also get a bit nervous if i don't know if i have a map, collection, or single item flowing through the same codepath

☝️ 3

@U5Y86G3KL can you be more specific about what is thing? Some example of a data that is either map, list, or scalar (and you don't know ahead of time)? The reason I ask, is sometimes the mistake is not to consider if there is a way to normalize the values to a certain kind of thing (e.g. all scalars can be instead a vector of one item), but hard to image something that is sometimes associative, sometimes ordered, and sometimes single.


But there are exceptions - e.g. parsing arbitrary clojure code and/or macros is one such example; and then you see tools like clojure.walk and that are optimized for those kinds of traversal patterns


hmmm I guess it would be any case where the map is understood of as a list of values that all need to be mapped over, but still want to maintain the keys just in case. the scalar case would be used when writing/debugging fun , and have it automatically generalize to a collection of thing good points though this might be a code smell


also I'm probably missing some idiom for processing maps, is there a shorter way to accomplish the following

;; apply fn to all map values

user> (do-to {:piza 3} (fn [x] (+ x 1)))
{:piza 4}

user> (into {} (map
        (fn [[k v]]
           k (+ v 1)})
        {:piza 3}))
{:piza 4}


if you are on 1.11.0 check out the new update-vals function


sweet, thanks!


Yeah, the pattern (zipmap (keys m) (map something (vals m)) keeps appearing in my code too. update-vals seems to be exactly that?


... it works. That is so much better.


@U11BV7MTK this seems common enough to me. I hit this whenever I'm processing nested structures


on a walk or something yes i agree. But I’ve found in #beginners those come up less and there’s sometimes general code like this and that is a bad call in my opinion.


I find it difficult to gauge whether a given Clojure library is supported and actively maintained by looking at the “Insights” tab in GitHub, etc. Some libraries have had little to no activity for years. I suspect this is because these libraries tend to be more complete and stable than their counterparts in other language ecosystems due to Clojure and its ethos. Thus, lack of activity is not necessarily a negative sign and could even be considered positive. What is the best way to tell whether a Clojure library is “active/stable and safe to use?”


Try it, if it solves your problem then it is safe to use.

metal 1
Godwin Ko13:03:09

read the source code, good library not only works as expected but also help you establish proper view of the underlying problem, just my two cents 🤞:skin-tone-2:

👍 1

I'm had this problem with Chouser/clojure-jna. I wanted to use it, but it hadn't been updated since eight years ago. Even though the release version is 1.0.0 - indicating some level of completeness - I couldn't use it because there was no documentation (beyond a very simple example). Reading the code wasn't helpful.

👍 1

Another approach is to ask a public forum, like Slack. People will often have good advice on the best libraries to use for many tasks.

👍 1

Hi. Beginner here. My goal: write web app, possibly mobile, too. (Solo/personal projects). But open to using it also for other apps such as ML/AI...Programming is a big hobby for me but if things turns into start-up/Saas, I will be happy, too. What are I am currently learning: Clojure fundamentals, and thanks to the Clojure community, Getting Clojure book has been working for me; I have covered most of it, and things are starting to click. My next steps are: • Practice Koans • Practice with good projects (that helps solidify my learning) • Then move to the suggested books/resources on web development • Start my own web app My Questions: • In general, what do you think about my plan? • Is there a web version of Clojure koans similar to that of Clojurescript • Any good suggestion on Clojure practice projects? Thanks


Personally, I'd skip the koans. To me, they're often more about solving some puzzle than they're about teaching you to use a language. And you'll come across plenty of puzzles when you try to write a project. And then start with something small and contained. Maybe a CLI tool that fetches and parses some data. Or a very small RESTful service. Perhaps a library that could be used as a component in one of your larger projects.

👍 2

Thanks for the tips!


I found 4Clojure - now at to be a valuable way to learn about a wider range of functions from clojure.core I have done videos for solving the first 60 challenges, using different approach and different functions from clojure.core (try solve the challenges yourself before looking at the videos)

practicalli-johnny16:03:43 has 0ver 80 challenges to solve and feedback on solutions can be sought from mentors via the site


Thank you for this! Will sure check out the mentioned resources.

James Amberger16:03:54

hello, I’m trying to use clj behind an http proxy

James Amberger16:03:51

Was hoping just setting $http_proxy would do it but apparently not. I’m on Debian/WSL2

James Amberger16:03:20

hmm /etc/java/ looks promising…

James Amberger16:03:19

unfortunately just editing that with my proxy settings doesn’t seem to have done it.

Alex Miller (Clojure team)16:03:36

For Maven repos, there are some things you can set in ~/.m2/settings.xml for http proxy


I'm reading "Programming Clojure" at the moment, afterwards I'll probably start writing some toy programs. Is the 2015 book "Clojure Applied" still a good read or are there better choices for a second Clojure book?

Alex Miller (Clojure team)16:03:08

There are a few parts that need a refresh but I think most of it is still useful

👍 1
Cora (she/her)16:03:56

going to also suggest Getting Clojure, if you're looking for books. it's incredible


Hello, I just started learning Clojure. I see Clojure community favor Emacs. What is the advantage of using Emacs over others IDE (In my case IntelliJ with for Clojure?

Cora (she/her)16:03:49

not much tbh, especially if you're used to intellij already

Cora (she/her)16:03:00

use the editor you know, imo

☝️ 8
t-hanks 1

As of last year's Clojure survey, Emacs is used by about 43-44% of Clojurians, followed by IntelliJ/Cursive at 31-32%, and then VS Code at 13% (steadily climbing, year on year). If you're familiar with IntelliJ, I'd recommend sticking with it and using Cursive. The #cursive is a great place to get support and it is a well-maintained system.

👍 2

emacs is a benefit in that all the plugins work together - if i install a new movement mode, i can use it in my buffers for any lang, not just clojure - for me personally, its a combo of emacs being my entire env for irc, email, usenet, editing, reading etc - and i do it all in non-gui/tty mode as a preference. most others cant do that, but as others said, if just looking from a clojure pov and never branching beyond, may as well use what you know


unlike most editors, if you ask #emacs on irc to convince you to use the editor, no one will try to convince you to use it. i love that i can do anything in it - and the workflow to develop a package is very clojure esque - repl driven, and its free as in freedom foss, an ideological gain compared to closed source stuff


@U038FTEBZFX As you can see, #emacs users love Emacs (and will be very helpful if you do decide to use it). I used Emacs on and off for twenty years, dating back to the 17.x versions, and used it for several years with Clojure too. I found it was a lot of effort to keep it properly configured and updated (without breaking -- package maintainers don't seem very careful about playing nice with other packages sometimes). I tried multiple configurations -- several heavily-curated Clojure-based ones as well as a couple of my own, from scratch, ones -- before I finally just abandoned Emacs and switched to Atom, initially, and then VS Code. But it's a very subjective issue.

😄 1
👍 1

The only Emacs users that will tell you to use Emacs are Common Lisp programmers, but that's out of necessity and survival.

😄 1

There is strong support for neovim + conjure and coc (Conjure also supports other lisp dialects too)


and nevovim + vim-fireplace and other nice things like neovim + treesitter.


If you prefer using IntelliJ then Cursive may be the most appropriate choice There are many other Clojure aware editors you could evaluate, which should all have the basic features


Historical Emacs had the best support for the Clojure language in the early days. This built up a base of people using Emacs, as well as helping attract existing Emacs users to Clojure. I would argue that Emacs Cider still has the best support for Clojure, especially when taking a REPL driven development approach. The REPL approach doesn't seem as prevalent in Cursive, but I've only had to use it in some tech interviews (so not much chance to evaluate it)


As others have said, using the editor you already know is probably your best option. But if you want to try something other than what you know (IntelliJ with Cursive), I recommend trying Visual Studio Code with the Calva extension if you don’t have prior experience with Emacs. In my opinion, it's more beginner-friendly, which will allow you to focus on learning Clojure. And you will get a lot of help in the #vscode and #calva channels. You can always pick up Emacs later on if you want. My advice would be not to learn too many new things at once because it can quickly become overwhelming. But that’s just my personal preference. What works for me is not necessarily what works for you.


IntelliJ and Cursive are fine and in the Clojure mainstream. Signed, Common Lisper who does not use Emacs.

Cora (she/her)14:03:00

the great thing about emacs is that I can make it do anything I like. that is also the bad thing about emacs

😄 3

will put it on the list, thanks