This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-25
Channels
- # adventofcode (18)
- # announcements (10)
- # beginners (59)
- # calva (9)
- # cider (1)
- # clojure (43)
- # clojure-austin (1)
- # clojure-europe (6)
- # clojure-italy (2)
- # clojure-nl (1)
- # clojure-uk (3)
- # clojurescript (8)
- # cursive (3)
- # emacs (3)
- # fulcro (3)
- # hoplon (1)
- # klipse (1)
- # off-topic (24)
- # reagent (2)
- # reitit (1)
- # shadow-cljs (41)
- # specter (5)
- # vim (1)
@stardiviner You can add JAR files as dependencies in deps.edn
using a coordinate of {:local/root "/path/to/the/file.jar"}
for example (from our deps.edn
file at work):
com.newrelic.metrics/publish
{:local/root "/var/www/worldsingles/build/lib/metrics_publish-1.0.0.jar"}
I also use that approach for my REBL set up
:rebl ; start REBL and a Socket REPL server
{:extra-deps {ws/dev {:local/root "../dev"}
org.clojure/core.async {}
compliment {:mvn/version "RELEASE"}
com.stuarthalloway/reflector
{:git/url ""
:sha "58565dda87195478843d7cfdb71371ed29a573bd"}
com.cognitect/rebl
{:local/root "/Developer/REBL-0.9.109/REBL-0.9.109.jar"}}
:main-opts ["-m" "ws.dev.repl"]}
(note: we use :override-deps
as well to specify the version for several dependencies, hence the {}
for core.async
here)That's a nice mix of overridden deps, Maven deps (with "RELEASE"
pulling in the latest stable available release -- only do this for dev-time tools, if at all, never for production deps!), Git deps, and local JAR files, and also a local subproject (`../dev`) which is where we keep our dev-only tooling in our subproject.
There is one place I still blur. Use :override-deps {org.clojure/core.async {....}}
for override specify version for dependency, right?
If I use coordinate like {org.clojure/core.async {}}
keep empty {}
is like using Maven deps's "RELEASE"
, right?
No. The empty {}
must be specifically overridden. We have a :defaults
alias that includes :override-deps
to specify all of the "pinned" versions we want to use across all our subprojects.
Even if a version was actually specified above in that :rebl
alias, the version specified in our :override-deps
will take precedence.
We use this in some cases to test against a local, modified version of a project. For example, I'm working on expectations
locally and when I want to test against that version instead of the regular published version we normally use, I can specify -A:exp-dev
which is defined as
:exp-dev {:override-deps {expectations {:local/root "/Developer/workspace/expectations"}}}
Normally, this dependency would be used
expectations {:mvn/version "2.2.0-rc3"
:exclusions [joda-time]}
(unless we run tests with :exp-dev
added to the aliases).Does that help @stardiviner?
I see. Thanks @seancorfield, Sorry for late response, my network for Slack is not stable.
How do I write a function that works like, say, *
, so that I can throw additional arguments at it like (* 2 3 4)
.
> (defn multiply [a1 a2] (* a1 a2))
gives:
(multiply 2 3 4)
ArityException Wrong number of args (3) passed to: user/multiply clojure.lang.AFn.throwArity (AFn.java:429)
@simon223 If the operation admits it, one nice pattern is to have a variadic arity delegate to the 2-arity using reduce
. See, for example, https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L2613-L2618
You need a "base" binary operation, so if implementing something like multiply
and you had a binary *
, you could do
(defn multiply
([] 1)
([x] x)
([x y] (* x y))
([x y & more] (reduce multiply (multiply x y) more)))
(defn multiply
([] 1)
([x] x)
([x y] (* x y))
([& more] (reduce multiply more)))
you can't just do that i guess (ignoring basic syntax issues i assume are present)A slightly more elaborate average
example is in ClojureScript: Up and Running on p. 30. It is good in that the variadic arity isn't just a simple reduce
with the 2-arity.
Is there any way to mark a function, so it doesn't get reloaded by cider-refresh
or clojure.tools.namespace.repl/refresh
?
@funyako.funyao156 You can mark a whole namespace to not be reloaded but not an individual function.
(you can't unload/reload a namespace and preserve any elements of it)
See https://github.com/clojure/tools.namespace#disabling-refresh-in-a-namespace if you want to mark a whole namespace as not unloadable/not reloadable.
@seancorfield Thank you!
Is there a portable way (cljs/clj) to get an stream out of a string?
I found with-in-str
but I am looking for an alternative that does not bind to *1*
.
in other words, is there a portable clj/cljs function equivalent to the java function java.io.StringReader
?
I'm trying to selectively render my page and I want to chain a bunch of if statements
but doing (if (condition) (do (if ) (if (if )) (if ))) does not play.
and do-if kinda doesn't even make sense. but i'm not sure how to group many ifs
maybe cond is useful for you? https://clojuredocs.org/clojure.core/cond
Also, if you have something that looks like
(if test
(do
statement1
statement2))
that could be converted to
(when test
statement1
statement2)
@sova Are you trying to conditionally put together a data structure or string? Consider that (do (expr1) (expr2))
will only return the value of (expr2)
-- the value of (expr1)
will be thrown away.
If you're building a string, you'll need to call str
inside each "block" of values you want to append
(if (condition)
(str (if ) (if (str (if ))) (if )))
sort of thingIf you're build a data structure, then cond->
and into
(for vectors) or merge
(for maps) will work better (but, again, every expression result needs to be merged in or conditionally conj'd in (with into
).
Note that for merge
, you can have nil
values so it's often easier to write
(merge {:base "stuff"}
(when cond-1
{:some "more"})
(if cond-2
{:and "more"}
{:else "teh end"}))
Just upgraded Leiningen on macOS 10.14.2 and now it is broken:
✝ ~ lein repl
Warning: implicit middleware found: cider-nrepl.plugin/middleware
Please declare all middleware in :middleware as implicit loading is deprecated.
Error loading cider.piggieback: java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter, compiling:(cljs/util.cljc:1:1)
Exception in thread "Thread-1" java.lang.RuntimeException: Unable to resolve var: cider.piggieback/wrap-cljs-repl in this context, compiling:(NO_SOURCE_PATH:0:0)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6875)
at clojure.lang.Compiler.analyze(Compiler.java:6669)
at clojure.lang.Compiler.analyze(Compiler.java:6625)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3834)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6870)
at clojure.lang.Compiler.analyze(Compiler.java:6669)
at clojure.lang.Compiler.analyze(Compiler.java:6625)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3834)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6870)
at clojure.lang.Compiler.analyze(Compiler.java:6669)
at clojure.lang.Compiler.access$300(Compiler.java:38)
at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6269)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6868)
at clojure.lang.Compiler.analyze(Compiler.java:6669)
at clojure.lang.Compiler.analyze(Compiler.java:6625)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6001)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5380)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3972)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6866)
at clojure.lang.Compiler.analyze(Compiler.java:6669)
at clojure.lang.Compiler.eval(Compiler.java:6924)
at clojure.lang.Compiler.eval(Compiler.java:6917)
at clojure.lang.Compiler.eval(Compiler.java:6917)
at clojure.lang.Compiler.eval(Compiler.java:6890)
at clojure.core$eval.invokeStatic(core.clj:3105)
at clojure.core$eval.invoke(core.clj:3101)
at leiningen.core.eval$fn__4201.invokeStatic(eval.clj:343)
at leiningen.core.eval$fn__4201.invoke(eval.clj:333)
at clojure.lang.MultiFn.invoke(MultiFn.java:233)
at leiningen.core.eval$eval_in_project.invokeStatic(eval.clj:367)
at leiningen.core.eval$eval_in_project.invoke(eval.clj:357)
at leiningen.repl$server$fn__5963.invoke(repl.clj:278)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.core$apply.invokeStatic(core.clj:646)
at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1881)
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1881)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.core$apply.invokeStatic(core.clj:650)
at clojure.core$bound_fn_STAR_$fn__4671.doInvoke(core.clj:1911)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.AFn.run(AFn.java:22)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.RuntimeException: Unable to resolve var: cider.piggieback/wrap-cljs-repl in this context
at clojure.lang.Util.runtimeException(Util.java:221)
at clojure.lang.Compiler$TheVarExpr$Parser.parse(Compiler.java:710)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6868)
... 44 more
✝ ~ java --version
openjdk 11.0.1 2018-10-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.1+13)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.1+13, mixed mode)
@sova What you want is a routing function. I recommend you to take a look at one of those libraries: - https://github.com/juxt/bidi - https://github.com/weavejester/ataraxy - https://github.com/metosin/reitit
Already removed everything from ~/.m2
and a new lein repl
installed many of them back, but lein repl
still is broken.
@tobias.vetter you seem to have some outdated middleware in your either in ~/.lein/profiles.clj
or your project.clj
. Try removing them
@U7ERLH6JX @seancorfield Thanks a lot. It works now!
Outdated stuff in ~/.lein/profiles.clj
is the number one most common cause of problems with Leiningen.
@seancorfield i'm building a string, maybe merge is the way for that. it's conditional renders for when a user is logged in.