This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-05
Channels
- # beginners (135)
- # cider (30)
- # clara (66)
- # cljs-dev (18)
- # cljsrn (6)
- # clojure (115)
- # clojure-austin (1)
- # clojure-dev (10)
- # clojure-italy (7)
- # clojure-nl (1)
- # clojure-spec (18)
- # clojure-uk (26)
- # clojurescript (76)
- # cursive (2)
- # datomic (4)
- # devops (1)
- # emacs (19)
- # fulcro (159)
- # garden (3)
- # klipse (5)
- # leiningen (5)
- # off-topic (61)
- # om (7)
- # pedestal (6)
- # re-frame (17)
- # reagent (73)
- # ring-swagger (6)
- # rum (5)
- # shadow-cljs (60)
- # spacemacs (31)
- # specter (4)
- # vim (8)
- # yada (1)
does clojure.test have a convenient way to do a global fixture? as in creating an account once per test suite, then cleaning up afterword? the (use-fixtures)
is on a namespace level, not global, so can I use the namespace dependencies (or something similar) to ensure a catch-all file that’s loaded first?
If you’re using leiningen you can do global test setup code in a :injections vector within the project.clj and a jvm shutdown hook for cleanup
I’m sure there are other ways but that’s been one that has worked nicely for me.. I use that to start up the server exposed by my application and shut it down after the tests have run. It’s only needed when running on CI agents since if I’m working on the tests myself I’ll just do the setup in my repl
something like…
what do people use for linting clojure code? So far I’ve tried kibit, eastwood and joker, but all of these tools have lots of false postives.
joker works very well for me
what kind of false positives are you seeing?
strange, I'm not seeing those (with cljs)
for me joker works reasonably well. The biggest "unresolved symbol" issues are probably with clojure.test
(because of :refer :all
and clojure spec (`fdef` spec above the function)
You can also, I think, ignore some errors or, failing that, just grep through the output and remove warnings that you want to exclude. Hacky but it works
@U9CQNBXDX make sure you configure :known-macros
in .joker
file: https://github.com/candid82/joker#reducing-false-positives
just Cursive
There is a #graalvm channel. Even datomic works well (not sure about prod setup) https://gist.github.com/souenzzo/c4719d45e804767c97f6f5be1bcdd1c5
I covered a lot on the subject here: https://groups.google.com/d/msg/clojure/iBY6hwqqp5c/EsAaEJ9WCgAJ
In short, asking if "GrallVM works with Clojure" is most likely not the question you think you're asking 😄
I’m conj
ing onto a list and calling peek
on it. This seems to work for a while in my app until it doesn’t and I get java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IPersistentStack
. It is possible that conj
returns a different kind of list depending on the size or should I look elsewhere for a bug?
conj
does return different concrete implementations depending on size (e.g. array-map to hash-map), but not different collection types
I am using the clojure command line tool, it locks up, strace shows chasing the POMs, on a cyclic dependency (hickey-rage-face) in [org.apache.xmlgraphics/batik-transcoder "1.7"] similar to https://github.com/technomancy/leiningen/issues/1127 - does anyone know a workaround ? @alexmiller
I was burnt by this in gradle, 7 years ago, to the point of submitting a pull-request https://github.com/gradle/gradle/pull/13/commits/cebaae69dd21049a11240b320c00e79e9ae20a2b I think that time the library was apache fop ...
What's the JVM equivalent of the cljs.test/async
macro? https://github.com/clojure/clojurescript-site/blob/master/content/tools/testing.adoc#async-testing
...I guess the cljs test runner is asynchronous and the JVM one not, or something to that effect
@U45T93RA6 on clj there isn't generally a problem with testing async things - you generally get a promise or chan result which you can deref
or <!!
respectively, neither of which you can do on cljs
I am trying to bring up a service using compojure-api and the swagger-ui seems to have auto-sorted.... is there some way to control the sorting of the JSON responses?
can you explain what you are trying to accomplish @sidiv14.it. It sounds like you are trying to sort a hashmap which is asking more from a data structure than it is willing to give
json objects are unordered. so there's no guaranteeing that your sorting would be honored
you could wrap whatever objects you want sorted in an array, the order would be honored then.
I suppose you could see if there's a JSON serializer that sorts keys, but why would you want/need that?
but there's no guarantee that a client would treat the serialized order as important
I am writing a simple parser/compiler for a hiccup-like DSL. atm I’m using a protocol that dispatches on the type of the first element in the vector, e.g. if it’s a keyword, symbol.
I’d like to allow a consumer to extend the parser in a way that isn’t just based on type, though. such as for a special :keyword
, transform it in some way
protocols don’t really seem to work well for this. but also, multimethods kind of fall short for this too it feels like.
is there a common pattern to allow consumers of a library to extend functionality this way?
what if your multimethod first tried to match on the value, and if nothing found, then attempted to dispatch on the type?
(defmulti dsl-type-based type)
(defmulti dsl-value-based identity)
(defmethod dsl-value-based :default [x] (dsl-value-based x))
I was thinking of allowing a consumer to pass in a custom predicate. But maybe I don't need to be that flexible
@lilactown expand on your reason for not using multi-methods though, they're extremely flexible
(defn d1 [x] (->> x (take 2) vec))
(defn d2 [x] (-> x first :type))
(defn dispatcher [x] (let [f (first x)] (if (fn? f) (f (rest x)) f)))
(defmulti mfoo dispatcher)
(defmethod mfoo :bar [x] "is keyword dispatch")
(defmethod mfoo [:foo :bar] [x] "double keyword")
(defmethod mfoo :my-type [x] "special type")
Would something like this work for you? @lilactown Basically you extend the dispatcher by 'passing in' custom dispatchers. Or (haven't thought this out), maybe have the dispatcher itself be a multimethod
@lilactown If one were to use ‘spec’ how would you do without multi-methods?
I suggest you take a look at spec, it fits perfectly for your use case and you can write a hiccup like parser using spec in 10-15 minutes.
hi everyone. where am I going wrong? 😄
(defn- resolve-video-provider
[url]
(condp (partial s/includes? url)
"youtube" "YouTube"
"vimeo" "Vimeo"))
@bravilogy condp
takes a binary predicate and an expression, followed by a sequence of alternating value / result clauses.
yeah, I followed the docs and to my understanding, that was supposed to work but I guess I don’t quite get it then
I thought I would refactor this
(defn- resolve-video-provider
[url]
(cond
(s/includes? url "youtube") "YouTube"
(s/includes? url "vimeo") "Vimeo"))
It's difficult with s/includes?
because condp
tests (pred test-expr expr)
where expr
is the initial expression and test-expr
is each of the values in the clauses that follow.
you'd need
(condp (fn [t e] (s/includes? e t)) url
"youtube" "YouTube"
"vimeo" "Vimeo")
jinx 🙂
The docstring/reference docs are not really very clear (IMO), but clojuredocs has good examples: http://clojuredocs.org/clojure.core/condp
(fn [{:keys [:keywords]}] keywords)
destructure with keywords is allowed. (fn [{:prefix/keys [:keywords]}] keywords)
destructure with namespaced keys keyword not allowed. intentional? bug?
We have a utility function at work, called flip
(taken from Haskell), so we could say
(condp (flip s/includes?) url
"youtube" "YouTube"
"vimeo" "Vimeo")
(defn flip
"Like partial except you supply everything but the first argument.
Also like Haskell's flip for single arity call."
([f] (fn [b a] (f a b)))
([f b] (fn [a] (f a b)))
([f b c] (fn [a] (f a b c)))
([f b c d & more]
(fn [a] (apply f a b c d more))))
@mg you can use qualified-`keys`:
user=> ( (fn [{:a/keys [b c]}] (println b c)) {:a/b 1 :a/c 2} )
1 2
nil
a new version is {:prefix/keys [without-prefix]}
. however, when using a keyword there (as opposed to just a symbol) it barfs with :prefix/keys
but not on :keys
@seancorfield I use flip
all the time in js
from ramda.js
library 😄 that’s a neat implementation, thank you
@dpsutton I would say it's intentional because :a/k
and :k
are different -- and I think it's weird that :k
is allowed inside [ .. ]
in the unqualified case.
understood. i can see a rationale either way. just was a bit surprising but makes sense
@seancorfield the 1-arity is kind of subtly different from the others and doesn’t quite match the docstring… I guess it’s semantically meaningless for fewer than 2 args
@michael.gaare Well, we don't have currying in Clojure -- and if the 1-arity was curried, it would be harder to use.
You couldn't use it in condp
for a start...
(but your point is well-taken)
@michael.gaare Yeah, it's a bit of an odd compromise due to the fundamental difference between Haskell and Clojure in terms of currying. Haskell doesn't need partial
at all, and Haskell's flip
can be fully defined in one arity.
I never quite understood why condp
was written that way, actually. It seems like it’s forcing you to give up some expressivity in terms of how you construct your predicate, and I don’t see what the benefit is
what would be the alternative in your view @michael.gaare?
So, something like:
(condq pred
test-1 result-1
test-2 :>> result-2)
where it calls (pred test-1)
, then (pred test-2)
...(since it could still pass (pred test-2)
as an argument to result-2
(as a function))
Basically I just removed all the references to expr
from condp
...
I guess there's maybe some hacky way to do both but I think it would be too clever?
Bravi: one function can take any number of arguments
(+) => 0 (+ 1) => 1 (+ 1 1) => 2 (+ 1 1 1) => 3 etc.
you can't really curry that
yeah true. I guess languages like Elm have currying by default because the functions know exactly how many args they’re going to take
I am new to using spec. Am trying to define spec for vector of keywords. Could someone please suggest a way to do this? Sample structure
[:val1 :val2]
(s/coll-of keyword?)