This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-03
Channels
- # aws (5)
- # beginners (67)
- # boot (30)
- # cider (55)
- # clara (7)
- # cljs-dev (6)
- # cljsjs (6)
- # cljsrn (1)
- # clojure (136)
- # clojure-brasil (2)
- # clojure-dusseldorf (14)
- # clojure-finland (9)
- # clojure-italy (49)
- # clojure-nl (1)
- # clojure-romania (6)
- # clojure-russia (4)
- # clojure-uk (16)
- # clojurescript (136)
- # core-async (1)
- # cursive (21)
- # datomic (64)
- # fulcro (26)
- # hoplon (25)
- # jobs-discuss (53)
- # keechma (3)
- # leiningen (6)
- # luminus (11)
- # lumo (2)
- # off-topic (351)
- # om (1)
- # onyx (11)
- # parinfer (32)
- # portkey (9)
- # re-frame (45)
- # reagent (38)
- # shadow-cljs (60)
- # specter (9)
- # vim (8)
- # yada (22)
Does anybody know how to handle errors/exceptions in Clojure? especially if I have a function composition like
(->> (f x)
(g)
(h))
and every function can throw an error/exception, but I only want to call the next function if no error is thrown. Any ideas?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.
I’ve seen some other libs like https://github.com/scgilardi/slingshot or https://github.com/MichaelDrogalis/dire 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 https://github.com/funcool/cats 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: https://github.com/cloojure/tupelo#default-value-in-case-of-exception
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?)
@daniel.gomme but shouldn’t the predicate be written after the filter not after the coll
oh damn is it really that
my bad
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
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 😄
self-promo: https://www.youtube.com/watch?v=4ecC3jqHooc. You may read the summary first: https://curiousprogrammer.net/2017/05/12/clojure-development-workflow-with-spacemacs-and-cider/
But yes, you have to invest non-trivial time in the transition. Btw. there's also #spacemacs
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.
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.
https://practicalli.github.io/spacemacs/ is a nice resource that's specifically about spacemacs with clojure. @denisgrebennicov
@denisgrebennicov no shame in using an ide. I used emails for ten years and now I use cursive and it’s great
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 java.net.URL
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 java.net.URL since java.io.File 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?(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.
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.
a list of issues we found with the core specs in libs is at https://dev.clojure.org/display/design/Errors+found+with+core+specs
if you lein deps :tree
that will show you all your deps and you might be able to spot the offender
I don’t actually see the error you mention above in that list so maybe it’s newly found
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.