Fork me on GitHub

Hi, Im working on a http request that need to be have the following query parameters.  ?where=customerId="aa238c96-189c-4740-a881-8d16dbc51001" and that needs to be url encoded into this ?where=customerId%3D%22aa238c96-189c-4740-a881-8d16dbc51001%22 but I´m not able to figure it out.  Using Hato as http client library. Suggestions?


(hc/get "" {:query-params {"where" "customerId=\"aa238c96-189c-4740-a881-8d16dbc51001\""}}) did you tried this? sent request contains :query-string "where=customerId%3D%22aa238c96-189c-4740-a881-8d16dbc51001%22"

👍 3

I know it's application specific, but what flags do y'all usually set when running a clojure app in production?


@petr are you running in containers or something else?


Yes, in containers


what sort of information are you looking for?


I would make sure you have the correct garbage collector for your needs: G1 (default), parallel (throughput), or ZGC


if you're in containers, prefer using MaxRamPercentage rather than absolute Xmx memory settings


We are using kube, so the ram available to the container is already limited, so not setting xmx. The garbage collection flag is one I hadn't thought of. I was thinking about stuff like whether the default heap settings are adequate, etc


java respects cgroups, fyi it will not use all the available cgroup memory for heap


(not that you'd want that anyways)


Awesome. That's good to know!


Thank you


> the ram available to the container is already limited, so not setting xmx xmx has a default value, it does not default to "all the memory on this machine", so you need to use the flag to ensure all the memory you provide is used


oh I guess ghadi already said that


Yeah, the typical default for max heap is 1/4 of available memory - both in containers and host OS. Other than that I'd avoid tweaking other settings, at least iniitally. You may find other flags useful to have debugging info available when a problem happens, e.g. • -XX:+HeapDumpOnOutOfMemoryError-XX:-OmitStackTraceInFastThrow

Yosevu Kilonzo17:08:33

Hello, can test.check be used with ClojureScript?


Haven't used it with CLJS personally though


Quick question: if I want to read a file from the users home dir, a Config file like a .zshrc, how do I get clojure to find that dir?


@dev-hartmann (System/getProperty "user.home")


@seancorfield thanks, will try that!


There are several properties that are useful: you can get a hash map of all of them with (System/getProperties):

dev=> (-> (System/getProperties) (keys) (sort))
("clojure.basis" "clojure.core.async.go-checking" "" "file.encoding" "file.separator" "ftp.nonProxyHosts" "http.nonProxyHosts" "java.class.path" "java.class.version" "java.home" "" "java.library.path" "java.protocol.handler.pkgs" "" "java.runtime.version" "" "java.specification.vendor" "java.specification.version" "java.vendor" "java.vendor.url" "java.vendor.url.bug" "java.vendor.version" "java.version" "" "java.vm.compressedOopsMode" "" "" "" "java.vm.specification.vendor" "java.vm.specification.version" "java.vm.vendor" "java.vm.version" "javafx.runtime.version" "javafx.version" "jdk.debug" "line.separator" "log4j2.configurationFile" "logged-future" "os.arch" "" "os.version" "path.separator" "socksNonProxyHosts" "" "sun.boot.library.path" "sun.cpu.endian" "sun.font.fontmanager" "" "" "" "sun.jnu.encoding" "" "" "user.dir" "user.home" "user.language" "" "user.timezone" "vlaaad.reveal.prefs")
That's in our dev setup so some of those are set by us at startup of the REPL but most of them are standard/built-in for Java itself.


Ah, that’s really useful, thx for the info! My Java knowledge is somewhat lacking


If this is the case, then you may want to know about the File type in Java, since this gives you portable access to a file you want to open. The Clojure approach for talking to files on the JVM is in the namespace. You can then create a File object with , which can be used as the argument for opening a file, or just sending to the slurp function. e.g.

(require '[ :as io])

(slurp (io/file (System/getProperty "user.home") ".zshrc"))


The file function is useful here, because you give it the directory as the first arg, and the filename as the second without doing any string manipulation to build a path


@U051N6TTC thank you very much, that’s the approach I endend up taking 👌:skin-tone-4:


thanks again @U051N6TTC ended up using exactly this to read and create my applications config file!

👍 2

Team, I was searching in a internet, I am trying to find good resource to learn and become expert in clojure macros, Can anyone help me with link please


1. Understanding the Clojure evaluation model. 2. Awing at their beauty and power. 3. Awing at the fact that Clojure (and other lisps for that matter) have only a handful of special forms and everything else is defined as a macro. 4. Macroexpanding a ton. 5. Understanding the use of quote, syntax-quote, unquote-splice, gensym. 6. Properly understanding that their use is when you want to transform the source code before evaluation. 7. Finding the right use case for a macro, and checking if the macro emits the source that you expect by constantly macroexpanding your macro from the REPL. 8. Developing a sense for when to use them.

Cora (she/her)18:08:01

I'm not sure how good it is but pragprog has a book called "Mastering Clojure Macros" from 2014

Cora (she/her)18:08:23

I own it but have never read it 😅


same! :rolling_on_the_floor_laughing:

😂 3

Well, I did browse it a little


But I felt comfortable with creating macros after reading the relevant parts of “The Joy of Clojure”


This book I have not read yet, let me!


> I own it but have never read it Symmetric with my macrology. I read them, but never write them :grinning_face_with_one_large_and_one_small_eye:


I’d written macros before, but The Joy of Clojure really solidified how to do it (and more importantly, how to avoid using them). The most important parts of macro authorship are: • Avoiding writing macros • When you DO write a macro, you should usually minimize the work in the macro and write helper functions • Understanding quoting and unquoting

💯 3
Cora (she/her)18:08:37

there's another book I haven't read

Cora (she/her)18:08:08

I feel like I'm a bit of a fleabag clojurian

Cora (she/her)18:08:35

but I kind of figured out those three points on my own, so maybe I'm doing ok?

Cora (she/her)18:08:02

which I'm about to delete


I started out by reading “Programming Clojure” by Stu Halloway (back when the 1st edition was current). After that I believe that I was a competent Clojurista, but I often felt like I wasn’t necessarily being idiomatic in the language. Then I read The Joy of Clojure in 2011, and I finally felt like I got the language


I think some experience with formal systems / symbolic logic (so something like godel escher bach) and the notion of logics and metalogics helps a lot

Cora (she/her)18:08:24

I have no idea what you just said @U0NCTKEV8

Cora (she/her)18:08:30

see: I'm a fleabag programmer 😂

Cora (she/her)18:08:02

@U051N6TTC it was Getting Clojure that did it for me, such a great book. really a great teaching resource, the pacing and rhythm and content mix is just 😚👌


> The most important parts of macro authorship are: > ... + to all of quoll's points, with small additions: clojure.walk/macroexpand-all is a good friend. I like to run it ever time I use a new macro.

user=> (clojure.walk/macroexpand-all '(or (even? 3) (even? 42)))

(let* [or__5516__auto__ (even? 3)] (if or__5516__auto__ or__5516__auto__ (even? 42)))
Plus, definitely re-write macros you see in the wild, and play with syntax quoting rules to see the changing effect (e.g. the or macro featured above). Fiddle and macroexpand... it will help improve intuitions about how macros work in Clojure.


I macroexpand all the time. It’s especially useful when you’re trying to explain things to people. Like, how do the threading macros work? How does destructuring work? etc


"Macros are also just functions of data -> to -> data, except they run at compile-time." ... It took me a good while to properly grok this concept.


I do wish macroexpansion would expand to bad forms rather than throw spec errors when you are diagnosing bad forms


Like if it expanded to (let [single] body) it would show that expansion rather than spec error out

Cora (she/her)18:08:01

I work with Daniel Solano Gómez and wish I could capture how he iteratively develops macros because it was so cool to watch

Cora (she/her)18:08:57

also he's a fantastic D&D DM now lol


@U11BV7MTK I guess let is a special case since it tries to macroexpand let to let* . The following doesn't throw,

(macroexpand-1 '(let* [8]))


@UMPJRJU9E Yeah, several of Clojure's "Special Forms" are implemented as macros that expand to the actual, underlying special form. Like fn is a macro implemented on top of fn*, in addition to let, etc.


(there was a thread some time back where a new Clojure developer was very surprised that some things listed as Special Forms were actually Clojure macros that expanded to mostly undocumented stuff)


1. Understanding the Clojure evaluation model. 2. Awing at their beauty and power. 3. Awing at the fact that Clojure (and other lisps for that matter) have only a handful of special forms and everything else is defined as a macro. 4. Macroexpanding a ton. 5. Understanding the use of quote, syntax-quote, unquote-splice, gensym. 6. Properly understanding that their use is when you want to transform the source code before evaluation. 7. Finding the right use case for a macro, and checking if the macro emits the source that you expect by constantly macroexpanding your macro from the REPL. 8. Developing a sense for when to use them.


IMHO you only need to think about macros as an absolute beginner or a highly specialized expert, in between things go best if you don't make new macros


or maybe that's just resentment from having to deal with APIs that force the usage of macros

Franco Gasperino18:08:53

My first frustration to your point was go blocks and function composition.

Jakub Zika19:08:32

Hi, I have got a coll of functions as:

Now I would like to map it on coll containing colls of same length as:
[[5 5] [6 6] [7 7]]
result should be (lazily): [[6 4] [7 5] [8 6]] Is there some function for this?


(map (fn [p] (map #(%1 %2) fn-coll p)) number-colls)


The first thing I thought of was juxt but that applies everything to the same value. But since you’re going down seqs together, applying the first to the second, then that sounded like using map with 2 seqs


(def fns [inc dec])
 (for [[fst snd] [[5 5] [6 6] [7 7]]]
   [((first fns) fst)
    ((second fns) snd)])


a suggestion from the peanut gallery:

user=> (for [[fst snd] [[5 5] [6 6] [7 7]]
                  :let [[f g] fns]]
              [(f fst) (g snd)])
([6 4] [7 5] [8 6])

🥜 3

Yup yup, I’d definitely introduce a let to make it more readable. Was in a hurry here I guess


(oh, also, you can use mapv instead of map to get the requested vector results)

Jakub Zika19:08:13

Thanks, works like a charm


Since your values are the same number repeated (ie. [5 5] ) then juxt would work on a seq of just [5 6 7] As in: (map (apply juxt fn-coll) [5 6 7]) But that’s just extrapolating from your example, rather than what you asked for

👏 3
Jakub Zika20:08:18

Yeah, it was just example - not really good one 🙂. I will use this one (map (fn [p] (map #(%1 %2) fn-coll p)) number-colls)


Just 2 comments then: 1. as I noted, you can use mapv rather than map if vectors matter to you. I don’t usually bother unless there’s need for it. 2. I called the argument p to mean “pair”, but it may make sense to change it, particularly since it’s written to take a function seq (along with argument seq) of arbitrary length

Jakub Zika06:08:30

Yeah, I get the code. I was just hoping that there is some “native” function for that.. something like zipmap but for functions and values 🙂


Hey all i'm using the luminus template and im working through Web Development with Clojure and I'm trying to access the basic index route of the app at / (by going to localhost:3000) and i get a null pointer exception with not much to go off of. Any ideas on how I might begin to debug?

user=> Fri Aug 06 23:40:51 CEST 2021 [worker-1] ERROR - GET /
	at java.base/java.util.concurrent.Executors$
	at java.base/
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.base/java.util.concurrent.ThreadPoolExecutor$
	at java.base/


@varun.jayaraman How did you create your project and have you changed the code since creating the project? i.e., does a brand new generated project not work, or do you only get this error after making changes?


(a common "gotcha" is folks adding a println to their handler, making it return nil instead of a Ring response)


yeah i made a couple of changes, but ive followed the book until page 21 (not sure if you also have the book yourself). but basically ive modified routes/home.clj to look like this:

(ns guestbook.routes.home
   [guestbook.layout :as layout]
   [guestbook.db.core :as db]
   [ :as io]
   [guestbook.middleware :as middleware]
   [ring.util.http-response :as response]))

(defn home-page [request]
    request "home.html"))

(defn save-message! [{:keys [params]}]
  (db/save-message! params)
  (response/found "/"))

(defn about-page [request]
  (layout/render request "about.html"))

(defn home-routes []
   {:middleware [middleware/wrap-csrf
   ["/" {:get home-page}]
   ["/about" {:get about-page}]
   ["/message" {:post save-message!}]])
And home.html looks like this:
{% extends "base.html" %}
{% block content %}
<div class="content">
  <div class="columns is-centered">
    <div class="column is-two-thirds">
      <!-- Content -->
{% endblock %}


i thought it might have something to do with a typo in my selmer template but i cant seem to see anything. and the route itself at / is dead simple, I can't imagine what is throwing the null pointer exception there. Unfortunately i'm quite a noob and am not sure how to even begin debugging this


i was wondering if maybe i could replace home.html with just rendering a simple string and seeing if it works, so something like:

(defn home-page [request]
    request "<html><body><p>hi</p></body></html>"))
But layout/render takes a filename that it automatically looks up in the resources folder i think, so that wont work 😕


oh sorry @seancorfield i created the project with lein new luminus guestbook --template-version 3.91 -- +h2 +http-kit


Yeah, I just dug the book out to take a look. There's a lot of moving parts between running that and page 21 🙂


ill try a brand new project and see if it works


hmm a brand new one does work :thinking_face:


A suggestion: if you git init after first creating the template and then add and commit each step along the way, you'll have an easier time reverting to a working version and also you'll have the specific diffs showing the changes you made between a working version and a non-working version.


yeah true. i probably should have initialized it as a git project from the beginning


i must have fudged a file somewhere by accident


(I generally recommend Clojure beginners start with just Ring and Compojure (or reitit) to learn the basics of web dev before attempting to use Luminus -- it's very complicated for a new-to-Clojure developer)


would you recommend it to someone who is an experienced web dev but just new to clojure?


(it being luminus)


No, if you're new-to-Clojure, regardless of background, start with something much simpler than the Luminus template.


hmm i see. ok

Cora (she/her)21:08:57

there's a good example full stack clojure/script app in the latest clojure morsels. it uses pedestal which isn't too bad


I see so many beginners stumble with Luminus. It's fine until something goes wrong but then there are so many libraries involved and so much going on that debugging an error is really tricky 😕


I’m an experienced web dev who has been learning Clojure for about the last 1.5 years (on and off) and I’ve found Ring and Compojure by itself to be pretty straightforward.


So @seancorfield’s advice is sound. Not that there was any questioning that fact. 😉

Cora (she/her)22:08:35

I think the closest thing to a rails or laravel in clojure is coast, but that still uses compojure

Cora (she/her)22:08:48

so you may as well just try that


To put it in perspective, that Luminus project (created via that command-line) has all these libraries in play:

:dependencies [[ch.qos.logback/logback-classic "1.2.3"]
                 [cheshire "5.10.0"]
                 [ "0.3.2"]
                 [com.h2database/h2 "1.4.200"]
                 [conman "0.9.1"]
                 [cprop "0.1.17"]
                 [expound "0.8.7"]
                 [funcool/struct "1.4.0"]
                 [luminus-http-kit "0.1.9"]
                 [luminus-migrations "0.7.1"]
                 [luminus-transit "0.1.2"]
                 [luminus/ring-ttl-session "0.3.3"]
                 [markdown-clj "1.10.5"]
                 [metosin/muuntaja "0.6.7"]
                 [metosin/reitit "0.5.10"]
                 [metosin/ring-http-response "0.9.1"]
                 [mount "0.1.16"]
                 [nrepl "0.8.3"]
                 [org.clojure/clojure "1.10.1"]
                 [org.clojure/tools.cli "1.0.194"]
                 [org.clojure/tools.logging "1.1.0"]
                 [org.webjars.npm/bulma "0.9.1"]
                 [org.webjars.npm/material-icons "0.3.1"]
                 [org.webjars/webjars-locator "0.40"]
                 [ring-webjars "0.2.0"]
                 [ring/ring-core "1.8.2"]
                 [ring/ring-defaults "0.3.2"]
                 [selmer "1.12.31"]]
compared to what you get with lein new compojure webapp:
:dependencies [[org.clojure/clojure "1.10.0"]
                 [compojure "1.6.1"]
                 [ring/ring-defaults "0.3.2"]]


makes sense


(and I also really dislike Mount and some of the other choices Luminus makes -- I especially don't think they are good choices for beginners)

Cora (she/her)22:08:51

well coast used to use compojure, I thought. I really ought to know this since I'm technically on the core team 😅


I ought to take a look at Coast some time. I sort of deliberately stay away from "framework-y" things in Clojure...

Cora (she/her)22:08:40

I really like mount, it's a head-scratcher for me why it's so polarizing

metal 3
❤️ 3

i used to be against frameworky things after rails but after using phoenix in the elixir world, i think i'm less dogmatic


but i'll go back to basics and maybe only touch luminus once i understand how to debug a bit more in clojure


I think it's telling that Pragmatic rate this book as intermediate-expert:


@varun.jayaraman Don't feel disheartened about tripping up with Luminus -- that happens to pretty much everyone who is trying to learn Clojure from that book I think. A lot of people suggest Getting Clojure as a really good book to learn Clojure from.

Cora (she/her)22:08:56

here's that full-stack example clojure app

Cora (she/her)22:08:30

it's all set up to deploy to heroku even, which is nice


It uses Pedestal -- how approachable is that for a beginner?

:deps    {com.github.seancorfield/next.jdbc {:mvn/version "1.2.674"}
           hiccup/hiccup                     {:mvn/version "2.0.0-alpha2"}
           io.pedestal/pedestal.jetty        {:mvn/version "0.5.9"}
           io.pedestal/pedestal.service      {:mvn/version "0.5.9"}
           org.clojure/clojure               {:mvn/version "1.10.3"}
           org.postgresql/postgresql         {:mvn/version "42.2.23"}}
(I looked at Pedestal when Cognitect first released it and thought it was pretty complex -- but there was next to no documentation for it back then either)

Cora (she/her)22:08:47

there are some tricky bits in there now that I look closer, maybe stay away from that


alright i do have Getting Clojure , maybe i'll work through that first

Cora (she/her)22:08:34

I love that book so much


i think i was getting impatient and just wanted to build something with clojure so i reached for the web dev book

Cora (she/her)22:08:38

also for when you want to practice some things and then see what other people did and learn tricks


If it helps, here's a simple web app example I put together: and the README links to a variant created by @admin055 that swaps out Compojure and Component for Reitit and Integrant so it's good to compare the two.

👍 3

awesome, thanks ill bookmark it

Cora (she/her)22:08:10

I do like this compojure template a little better since it's batteries-included


how does leiningen know about these different templates by the way? are they hardcoded into lein?


i.e. luminus, compojure-app, etc

Cora (she/her)22:08:46

sean would know


It searches for <template-name>/lein-template


or does it hit some remote repository of registered templates


clj-new for the Clojure CLI/`deps.edn` looks for <template-name>/clj-template but also supports Leiningen templates (but the latter mostly generate Leiningen-based projects).


(there also a few simple templates built into both tools: app, lib, and plugin I think for Leiningen? It's template for clj-new -- and clj-new also has polylith built-in)

Cora (she/her)22:08:49

when I was starting in clojure I did that, too, starting with luminus and then running into tons of problems and then giving up on the book and just going through getting clojure and exercism and playing with compojure

Cora (she/her)22:08:43

I had an advantage coming from elixir and it sounds like you do too :)