Fork me on GitHub
Denis G09:04:19

Does anybody know how to handle errors/exceptions in Clojure? especially if I have a function composition like

(->> (f x)
and every function can throw an error/exception, but I only want to call the next function if no error is thrown. Any ideas?


With exceptions, the next function will not be called by default.

Denis G09:04:33

But is it a clojury way of doing things?


If g throws, execution stops there... and resumes at the closest try/catch block. Or you get a stacktrace in your console.


I’m not the best person to answer that, but since Clojure doesn’t have any other error handling constructs, I’d say yes.

Denis G09:04:47

I’ve seen some other libs like or but don’t know if it’s a good idea


Can’t help with that much... but usually you need something better than exceptions in cases where you want to clean up or wrap the error in some other way to pass to your caller. In the simple case that you posted, exceptions usually suffice.


@denisgrebennicov There are some monadic libraries in clojure like but the usual answer that I got is that exceptions are the fact of life on the JVM so we need to live them => just use try-catch(-finally) at the appropriate level. you can also look at with-exception-default in tupelo lib:


Anyone know what on earth the IllegalArgumentException Don't know how to create ISeq from: clojure.core$some_QMARK_ exception means when doing something like (filter ['sym] some?)

Denis G10:04:04

@daniel.gomme but shouldn’t the predicate be written after the filter not after the coll

Denis G10:04:13

(filter pred coll)


oh damn is it really that


I should wake up properly


@daniel.gomme ISeq is the interface for a sequence; so the error message is saying 'can't create a sequence from blah'


Yeah, I see how that'd arise from them being the wrong way around, cheers 🙂


the “monad way” to handle exceptions, but once you start using all your functions must respect and use the failjure functions

Denis G10:04:29

Thank you guys, and BTW does anybody know some good how-to-start-guide for emacs/spacemacs? Just trying to move from IDE to spacemacs and it’s hard 😄


But yes, you have to invest non-trivial time in the transition. Btw. there's also #spacemacs

Denis G10:04:45

Yeap 😄 I’ve installed spacemacs and try to work in it. But … it’s hard 😄 All those key-bindings… Are you using Spacemacs yourself?


The great thing about spacemacs is that it makes learning easier - when you press SPC you will get a mini-buffer with categories of commands which you can explore further.

👍 4

Moreover, if you use GUI version, then Menubar is quite useful for finding useful commands.


Agreed @U06BE1L6T, I found spacemacs to be a relatively non-intrusive transition that allowed me to learn new stuff at my own pace. But I was coming to it from vim land, so I was already comfortable in evil mode.

frenata13:04:46 is a nice resource that's specifically about spacemacs with clojure. @denisgrebennicov

Denis G13:04:24

Perfect! Thanks 🙂


@denisgrebennicov no shame in using an ide. I used emails for ten years and now I use cursive and it’s great

Drew Verlee14:04:57

Anyone able to spot any problems with this implementation of depth first search?

(defn dfs
  [g n v]
  (cons n ;; add the node to the search path
        (mapcat #(dfs g % (conj v n)) ;; and do the same
                (remove v (n g))))) ;; for unvisited neighboring nodes

(dfs {:a #{:b}
      :b #{:c}
      :c #{}}
     :a #{:a})

;; => (:a :b :c)


What is tbe best way to read a static file from JAR file? Because (io/file (io/resource "templates/file.pdf)) returns nil when called from uberjar 😕 Note that is really there (tested with unzip) and it works in REPL


@petr.mensik You can just use (io/resource "templates/file.pdf") I believe. Pretty sure that's how we do it.


It returns a which you can slurp I believe, or you can call io/reader on it to get a BufferedReader.


(well, you wouldn't want to slurp a PDF I suspect 🙂 )


Thanks guys, that really works, I thought that I can call io/file on since accepts it in constructor 🙂


Uh, it's URI, not URL, that's why I guess 🙂


Is there a standard equivalent of zipmap that creates a sequence rather than a map? Something like

(defn zipseq [& seqs]
  (partition (count seqs)
             (apply interleave seqs)))
Or, is that the briefest way to say it?


@deg That looks like (map vector seq1 seq2 seq3)

👍 4
Alex Miller (Clojure team)17:04:08

(apply map vector seqs)

👍 4

(I meant to use map vector directly instead of zipseq -- but, yeah, (defn zipseq [& seqs] (apply map vector seqs)) if you want zipseq)


Is there a good eureka client for clojure? I found this one but it hasn’t been updated for 3 years. Is there one that’s more current and compatible with the latest version of clojure?


@Will That project lists Clojure 1.6.0 in its project.clj file dependencies. That should be quite compatible with latest version of Clojure, too. I have no idea whether the code works to do what you want, but if it does not, I would be surprised if it was because of Clojure version issues.


I should clarify my question. At work we have a bunch of java microservices using Spring Boot to connect to a eureka discovery server I’m wondering if it would be possible to add a clojure microservice that could function the same the java microservices do and register itself with the discover server


Successive versions of Clojure since 1.3.0 have been mostly "add some new features, fix some bugs", with little or no "break things that worked with the previous version of Clojure"


I assumed it was a problem with it using an older version of clojure because of these errors I am getting. My import looks like this [eureka-client.core :as eureka] When running the server I’m getting this error

Exception in thread "main" clojure.lang.ExceptionInfo: Call to clojure.core/import did not conform to spec:
In: [0] val: clj_http.headers.clj-http.headers/HeaderMap fails spec: :clojure.core.specs.alpha/quotable-import-list at: [:args :class :spec] predicate: simple-symbol?
In: [0] val: clj_http.headers.clj-http.headers/HeaderMap fails spec: :clojure.core.specs.alpha/quotable-import-list at: [:args :class :quoted-spec] predicate: (cat :quote #{(quote quote)} :spec simple-symbol?)
In: [0] val: clj_http.headers.clj-http.headers/HeaderMap fails spec: :clojure.core.specs.alpha/package-list at: [:args :package-list :spec] predicate: (cat :package simple-symbol? :classes (* simple-symbol?))
In: [0] val: clj_http.headers.clj-http.headers/HeaderMap fails spec: :clojure.core.specs.alpha/quotable-import-list at: [:args :package-list :quoted-spec] predicate: (cat :quote #{(quote quote)} :spec :clojure.core.specs.alpha/package-list)


I am successfully import other libraries this same way, so I’m not sure quite what is wrong?


So this looks like it falls under the "little" in the "little or no" I mentioned earlier. You caught me 🙂


Clojure 1.9.0 tightened up the syntax permitted in :require and :import clauses of ns forms. Only a few projects contained forms that do not conform to the new restrictions. Looks like this is one of those few.


Or perhaps it depends on another project that is one of those few.


(ns eureka-client.core
  (:require [clj-http.client :as http]
            [clojure.set :refer [rename-keys]]
            [clojure.core.cache :as cache]))


The error might be in the version of clj-http that eureka depends upon, perhaps.


I did find this one that is supposed to work with clojure v1.8 but i am getting the same error, so would it be a problem with the other libraries I’m importing?


If you want to quickly try out eureka without these errors, you could try using Clojure 1.8 instead of Clojure 1.9. The main differences between those versions of Clojure are the addition of Clojure spec. If you are not intending to use Clojure spec right away, Clojure 1.8 will not give those errors and let you proceed to experiment with eureka.


I would expect that updating eureka and/or its dependencies to work with Clojure 1.9 is probably not a big amount of work, but is probably a distraction from your current goals.


I am just learning clojure and trying to get some of the developers at work to try it.


Their first question was if it would integrate with our current java services and the discovery server we are using


I was hoping to find an easy solution. If i was to debug and find the problem where would I start?


Makes sense. There are others who could answer that question backed by much more experience than I can.

Alex Miller (Clojure team)20:04:57

if you lein deps :tree that will show you all your deps and you might be able to spot the offender

Alex Miller (Clojure team)20:04:53

I don’t actually see the error you mention above in that list so maybe it’s newly found


Am I just looking for duplicate dependencies?


I noticed that the eureka project you mentioned depends on version 1.0.0 of the clj-http library, which is several years old, and eventually depend upon clj-tuple 0.1.5, which is an older version than one on the list of projects that gives an error with Clojure 1.9.0.


I do not know whether the clj-http library API has changed in a way since version 1.0.0 that the existing eureka project code would work with a more recent version of clj-http or not.