This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-05
Channels
- # announcements (5)
- # beginners (49)
- # boot (9)
- # calva (34)
- # cider (9)
- # clara (18)
- # clj-kondo (1)
- # cljsrn (7)
- # clojure (196)
- # clojure-dev (4)
- # clojure-europe (11)
- # clojure-france (3)
- # clojure-nl (13)
- # clojure-norway (2)
- # clojure-spec (8)
- # clojure-uk (85)
- # clojurescript (87)
- # clojurex (202)
- # core-logic (6)
- # data-science (6)
- # datomic (9)
- # dirac (1)
- # duct (93)
- # emacs (9)
- # events (1)
- # fulcro (22)
- # hoplon (30)
- # jackdaw (10)
- # keechma (1)
- # leiningen (5)
- # malli (17)
- # off-topic (9)
- # other-languages (3)
- # pedestal (7)
- # re-frame (3)
- # reagent (5)
- # reitit (9)
- # remote-jobs (6)
- # rewrite-clj (80)
- # ring (2)
- # shadow-cljs (191)
- # tools-deps (54)
- # vim (14)
- # xtdb (7)
if you aren't sure, the right answer is usually atom
most people never need agent
ref
improves on atom when there's enough contention that it becomes a perf bottleneck that matters
(eg. holding many values in one hash-map in an atom, vs. synchronized updates to a group of refs)
Thanks! What's the appropriate way to wait for, say, a bunch of HTTP requests without blocking?
usually the simplest thing for that is a future, which is an object that will eventually provide a result or error, and you can ask it if it's completed etc.
it uses a thread pool under the hood
(ins)user=> (doc future)
-------------------------
clojure.core/future
([& body])
Macro
Takes a body of expressions and yields a future object that will
invoke the body in another thread, and will cache the result and
return it on all subsequent calls to deref/@. If the computation has
not yet finished, calls to deref/@ will block, unless the variant of
deref with timeout is used. See also - realized?.
nil
(ins)user=> (future (+ 1 1))
#object[clojure.core$future_call$reify__8439 0x235a0c16 {:status :ready, :val 2}]
(ins)user=> @*1
2
(ins)user=> (def err (future (/ 1 0)))
#'user/err
(ins)user=> @err
Execution error (ArithmeticException) at user/fn (REPL:1).
Divide by zero
(ins)user=> (future (Thread/sleep 20000))
#object[clojure.core$future_call$reify__8439 0x63fdab07 {:status :pending, :val nil}]
(ins)user=> ; deref / @ on above would not complete until 20 seconds after it was created
notice how err
doesn't actually bubble anything up until dereferenced
(the *1
variable is just a convenience, it lets you refer to the last result in the repl)
I was about to write someting like (contains? nil coll)
if it was elixir I would write Enum.member?
to check if list contains nil
but in documentation I saw contains?
for keys and there is no function like member?
btw the syntax is (contains? coll nil)
- for indexed / lookup collections only of course (sets, hash-maps)
(defn phones [p-list]
(->> p-list
(mapv #(re-matches #"^\d+$" %))
(WHAT TO WRITE HERE?)
))
(def correct ["2161234567" "5551234567" "8881234567"]) ;Expected TRUE
(def incorrect ["ABCDEFGHIJ" "55512a34567" "8881234567"])
(some nil? coll)
or the other contrapositive i guess, (every? some? coll)
depending if you are looking for the presence of nils or the absence of nils
the rationale is that contains?
is always constant time and you need to do a linear scan. The functions guarantee (or try to) indicate their cost across any abstraction they operate on
could someone please remind me how i might make the the following object seqable?
(first #datom[123456789123 1 "hello world" 987654321 true])
Don't know how to create ISeq from: datomic.client.impl.shared.datom.Datom
i remember using something like (defprotocol Datom ...)
and then (->Datom #[...] )
but i can't get the syntax quite right.however this doesn't look like a great thing to do. why do you want to be able to call first
on a datom?
yes, i was hoping to use first
and in the example above get back 123456789123
, and also to destructure the object in a let: (let [[a b c d e f] datom]])
.
> why? just for easier destructuring. i'm sure i did this a year ago in one little line of code.
that being said, i'm having trouble getting any value from the vector-looking object 😉
Can you call keys
on that datom? According to the docs, it looks like there's named key access to the fields in a datom...
Hmm, some of the examples look like :v
, :a
, :e
would works as keys... But there doesn't appear to be much documentation about accessing the elements of a datom directly.
And I've found another part of the docs that seems pretty clear that it's "just" a tuple so that jives with nth
working (and maybe vector destructuring which I thought only used nth
?).
for educational purposes i'll admit that i just assumed destructuring wouldn't work after i saw that first
failed.
You can look at the source of clojure.core/destructure
to see how that works. It is quite gnarly though.
Hi I am facing issue while installing clojure inside the docker..any pointers please. I am trying to install it with Java 11
@jainsaurabh78 Maybe you can explain what commands you are trying to run and how they are failing?
I am working on tap-mssql for pipelinewise that is written in clojure language. To create an image of my pipelinewise doker I need to install clojure as well that requires leiningen (RUN curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > lein && mv lein /usr/local/bin/lein && chmod a+x /usr/local/bin/lein). when it installs clojure it is giving this error java.io.IOException: Cannot run program "/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java" (in directory "/pipelinewise/.virtualenvs/tap-mssql"): error=2, No such file or directory at java.lang.ProcessBuilder.start (ProcessBuilder.java:1128) java.lang.ProcessBuilder.start (ProcessBuilder.java:1071) java.lang.Runtime.exec (Runtime.java:591) jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-2) jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke (Method.java:566) clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:167) clojure.lang.Reflector.invokeInstanceMethod (Reflector.java:102) leiningen.core.eval$sh.invokeStatic (eval.clj:179) leiningen.core.eval$sh.doInvoke (eval.clj:173) clojure.lang.RestFn.applyTo (RestFn.java:137)
I have version JAVA 11 installed but is it checking for 8..
lein itself is a single shell script, the place where it is looking for 8 shouldn't be hard to find
just doing a quick search in that script myself, it looks like if you export JAVA_CMD
to point to your java executable it should use that
it could be something incorrect from the parent env is leaking into the docker context
ok. checking for JAVA_CMD
regardless of why it's set wrong, you can probably fix your current issue by setting the right value when running lein
there's also LEIN_JAVA_COMMAND
which is less likely to be set accidentally, and takes precedence if both are set
Any suggestion how to set Lein_java_command and java_command
I tried setting up /usr/lib/jvm/java-11-openjdk-amd64 in JAVA_HOME variable but still it is looking for 8
these are environment variables, the easiest way is to use export
or set them directley eg. JAVA_CMD=/path/to/java lein
it's not even looking for JAVA_HOME