Fork me on GitHub

i've been banging my head against this bizarre error message for a while now, wondering if i can get some help:

(defn directions-to-lines [directions]
  ((reduce reduce-directions {:lines () :position [0 0]} directions)) :lines)
when i evaluate this function (directions-to-lines wire) i get Wrong number of args (0) passed to: clojure.lang.PersistentArrayMap class clojure.lang.ArityException, but when i evaluate the body directly:
((reduce reduce-directions {:lines () :position [0 0]} wire)) :lines)
the expression evaluates to the expected result. any ideas? i figured it out. my parentheses were mis-matched.

facepalm 8
Edward Hughes12:12:08

Happens to the best of us. Are you using an editor with paren-matching?


Check your parents, those are not the same expressions

👍 4

Hello, stupid question: how do I do nested loops? I need a classic

for i = 0; i< 10; i++
for j = 0; j< 10; j++


it’s a loop with two recurs?


no wait, it’s an if over two recurs??


that’s curious…also counterintuitive 😄


Do you absolutely need a loop? If you just need the i, j pairs, clojure.math.combinatorics/cartesian-product can get you all combinations of i, and j, which you can map a function (your inner loop body) over. Feels a bit more idiomatic to me, but I am equally beginner


I need to basically brute force all the combination until I found what I need.


cartesian-product is lazy?


I think so, yeah


that’s a nice solution than, I will try. Thanks.

Alex Miller (Clojure team)10:12:25

Nested dotines is prob easiest

Alex Miller (Clojure team)10:12:45

But it depends if you are making something (then use for)or doing side effects


How do I run a single clojure file from the CLI if I have a -main function? The filename is manhattan.clj and ns is manhattan.core but running clj manhattan.clj doesn't seem to be working when I just do a println in -main . It's not printing anything to the console.


@nicholas.jaunsen main methods can be executed with the -m option, but I think the file has to be on the classpath (typically in the src dir)


Ah, I just imported clojure.main and passed my entry point to the main function from that namespace

Eamonn Sullivan12:12:22

Hi all, I'm just getting started on Clojure/ClojureScript for a small-ish full-stack web app for my colleagues. After randomly stumbling around, I came up with a luminusweb/re-frame/graphql foundation and it seems to work OK (so far). However, I'm blown away by spec (I'm a Scala guy, usually) and I'd like to use that, in hopefully the right way from the start. Can anyone suggest any similar full-stack apps on github or elsewhere that I could study, preferably using spec in a non-trivial way?


Not a codebase like you're looking for, but this is a useful reference on the ways you can use spec.

👍 8
thanks3 4
Eamonn Sullivan15:12:03

I still have a load of really basic questions, such as where do people generally put the specs? In their own specs/ directory (separate from src/, for example)? Do you put all of the specs in one place, under one ns, or scattered about, together with modules you are spec-ing?


That's also a question I also have. From what I read it's in src/, either together in a specific ns or close to the functions they instrument


It depends. And that article answers that question as I recall?

Eamonn Sullivan16:12:49

Thanks. Yes, you did mention that you put the specs and predicates under a separate namespace. In src, I assume? I missed that the first time.


All source code goes under src so it is on the classpath. Test code goes under test and is added to the classpath for when you run tests.


An alternative option (which I find helpful) is to co-locate your specs with the ns they pertain to. e.g. if your folder structure was

I would put todo specific specs into the todo.clj file and if there are specs that don’t fit into any of the namespaces themselves, I move them to app…but this is a guideline and it really depends on your domain and app structure.


Another thing to note is I do not opt to spec everything, but rather, the edges of the application. For example, maybe only the public API fns would be spec’d or important implementation details.


(def pos
  {:u inc :d dec
   :r inc :l dec})

(defn path-inc [cord [k v]]
  (let [dir (if (contains? #{:u :d} k) 1 0)
        choose #(update % dir (pos k))]    
    (take v (rest (iterate choose cord)))))

(defn trace-line [start dirs]
  (let [llast #(last (last %))
        reducer (fn [acc dir]
                  (conj acc (path-inc (llast acc) dir)))]
    (->> dirs
         (reduce reducer [[start]])
         (partition 2)


having a weird issue with the trace-line function. For some reason it's returning a list of tuples and not a set of tuples even though I'm calling set in thread last macro


That seems difficult to understand given the code that you show. How certain are you that the code you show matches the code you are running? e.g. could you be running code older than what you have in your editor? Tried saving all files, starting a fresh REPL, and loading your code again?


ok, I quit the REPL and restarted it that fixed the issue. For some reason it wasn't updating the function def even though I reloaded the code several times


There are many many ways to reload code, depending upon editor /environment setup, so difficult for me to guess what might have been going wrong there.


In shadow-cljs, is there a way to re-enter the cljs-repl after leaving it with :cljs/quit ?


just start the CLJS repl again


@mitchell_clojure how did you start it in the first place?


just by running (shadow/repl :app) from the shadow nREPL server


running :cljs/quit takes me out to the user namespace and I am a little unclear on if the cljs repl persists or is reachable from there


Just note that when you exit it with :cljs/quit you're left in a namespace that doesn't contain the shadow alias


oh okay, so is it preferable to have two separate repls running?


IIRC (shadow.cljs.devtools.api/nrepl-select :app) would work there


following up to say this just worked! thanks again

🙂 4

oh awesome, that looks like exactly what I was looking for. will verify later when I get home! thank you very much!

simple_smile 4
Mehdi H.17:12:01

Hi everyone! I can't seem to be able to catch errors thrown using Pedestal. I have a transaction function to Datomic that throws a clojure.lang.ExceptionInfo exception in the datomic on-prem transactor, which, according to Datomic documention, should also be thrown in the peer, so in my case through the database interceptor that tries to transact the faulty data. None of my interceptors have an :error function, but I have used io.pedestal.interceptor.error/error-dispatch to catch the errors at the end of the process. It does not seem to work. • Does an interceptor need its :enter function to be used on the request to have its :error function used on the way out? • If so what is the proper way to user error-dispatch (the resulting interceptor is the first in the route) • any other thoughts as to why I am not catching it (it's a POST request and it returns 201 created even if it didn't happen...) Thanks!

Mehdi H.11:12:07

Nevermind, I found the issue in the code.


Is there a convenient way to use cider-load-buffer without having an associated file? I just have a scratch buffer and I jacked into cider and I want to load the buffer into the REPL and play without without having a file on disk, but trying to load the buffer gives "Buffer 'my-buffer' is not associated with a file"


I do not know the answer but wanted to point out that there is a #cider channel

👍 4