This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-29
Channels
- # aleph (2)
- # architecture (1)
- # beginners (5)
- # boot (7)
- # cider (24)
- # clara (28)
- # cljs-dev (7)
- # cljsjs (3)
- # cljsrn (24)
- # clojure (145)
- # clojure-italy (2)
- # clojure-nl (7)
- # clojure-uk (54)
- # clojurescript (159)
- # cursive (49)
- # data-science (8)
- # datomic (23)
- # editors (10)
- # emacs (2)
- # fulcro (123)
- # graphql (12)
- # hoplon (2)
- # java (23)
- # jobs (1)
- # jobs-discuss (2)
- # leiningen (17)
- # mount (5)
- # nrepl (5)
- # off-topic (20)
- # om (2)
- # onyx (25)
- # parinfer (2)
- # pedestal (1)
- # re-frame (8)
- # reagent (7)
- # ring-swagger (1)
- # shadow-cljs (24)
- # spacemacs (7)
- # specter (6)
- # tools-deps (7)
- # vim (2)
hi everyone. is there a shorter version to this?
(let [[butlast-args last-arg] [(butlast args) (last args)]])
I believe destructuring does not give such an ability But well, you can not use it here at all ad-hoc (butlast args) (last args) seems fine for me or (let [x (butlast args) y (last args)])
i thought there’d be a function specifically for doing that coz i’ve seen clojure do magic 😄
you could play with split-at (dec (count coll))
but i'm not sure how you can make this more terse
((juxt pop peek) (vector args))
user=> ((juxt pop peek) [1 2 3 4 5])
[[1 2 3 4] 5]
what I'm saying is that (juxt pop peek) is more concise than split-at etc.
user=> ((fn [& args] (let [[b l] ((juxt pop peek) (vec args))] {:b b :l l})) :a :b :c :d :e)
{:b [:a :b :c :d], :l :e}
(and fairly efficient too, compared to last
/`butlast`)
anyone using hugsql? Is there a way to import a file of definitions in another file? I have a bunch of snippets that I want to be used in each hugsql file I make.
HugSQL doesn't directly support an "include" of other SQL files, BUT you can concatenate two or more HugSQL files together as a string and use def-db-fns-from-string
. Something like: (hugsql/def-db-fns-from-string (str (slurp "file1.sql") (slurp "file2.sql)))
If I have a ns that looks like this:
(ns my-ns.core
(:gen-class))
(defn -main
[& args]
(println "------")
(prn "ARGS:" args)
(println "------"))
And I run this from a REPL:
(binding [*compile-path* "target/classes"]
(compile 'my-ns.core))
=> my-ns.core
How do I run that -main
function? I tried doing this but got Error: Could not find or load main class my-ns.core
. Also tried replacing the -
with _
, no dice.
java -cp 'target/classes/*' my-ns.core
Ah, the *
was causing the issue. Now getting Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/Var
. Do I also need to include Clojure on the cp?
depends how much you AOT, I've noticed that when I AOT I am only getting the immediate dependencies of my main. I'm not sure if this is intentional behaviour though.
@bronsa I noticed that only things I did :require
on from my main
were AOT'd, is that correct?
Is there some sort of cache for compile
? I have noticed that sometimes things in my :require
are included in *compile-path*
and sometimes they are not.
@bronsa is this what leiningen works really hard to workaround. I recall some workaround it performs.
@kennny no compilation cache but clojure won’t re-compile a clj file if the class file is more recent
@dominicm yes see https://dev.clojure.org/display/design/Transitive+AOT+Compilation (and https://dev.clojure.org/jira/browse/CLJ-322)
@bronsa hmm, this is not quite what I'm seeing though.
main depends on A.
A depends on B.
Only main and A get AOT'd when I compile
main.
Oh, I think I see what it is I'm using integrant, which has a load-namespaces
which is dynamic. Sorry for the noise. It's good to know I'm doing the right thing though (otherwise)
@kenny it might be that you have already require
d core.async
before compile
ing my-ns.core
you can replace your :require
s with e.g. :require core.async :reload-all
to force reloading
or you can use tools.namespace
to force unloading of the transitive dependencies for my-ns.core
Gotcha. Adding clojure to the cp doesn't seem to fix the issue.
java -cp target/classes:~/.m2/repository/org/clojure/clojure/1.9.0/clojure-1.9.0.jar my_ns.core
Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/Var
at my_ns.core.<clinit>(Unknown Source)
Caused by: java.lang.ClassNotFoundException: clojure.lang.Var
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
@metametadata your byplay library looks really interesting! Somewhat related to background job processing, I'm evaluating different scheduling libraries (scheduling as in "run this task 5 days from now"). Just wondering if you have any experience or preference with libraries like quartzite or monotony?
byplay
is somewhat abandoned, plus it doesn't support scheduling, I can't recommend it 🙂 I recently briefly evaluated other solutions for work and would just go with Quartz
or maybe a Clojure wrapper on top of it. It's mature, supports persistence and scheduling.
Just trying to get a deeper understanding of how this works. Also, I wrote a clj
uberjar task that does not work when dependencies on included and I want to figure out why.
Any ideas here?
java -cp target/classes:$HOME/.m2/repository/org/clojure/clojure/1.9.0/clojure-1.9.0.jar:$HOME/.m2/repository/org/clojure/spec.alpha/0.1.143/spec.alpha-0.1.143.jar uberjar_sample.core
https://pastebin.com/8NmzsFLSBasically Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type
. Haven't seen that class before.
I assume core.async is using that. Is there a reason that wasn't included when I AOT'ed my ns?
@kenny if you want a convenient way to "dump out" the libs juxt/pack.alpha just added support for doing that in a particular branch. It's also good for uberjars, if you're looking for a library for that.
@kenny it's called "skinnyjar", latest commit is 800afc066907e31fe90ce4df4f519e6224116867
the reason why t.a.jvm
doesn’t use the bundled one is that up until 2 days ago clojure shipped an ancient version of ASM and we were using modern APIs that just didn’t exist in the version bundled with clojure
the ASM version got bumped because the class version and minimum jvm requirement got bumped from 1.6 to 1.8 which means we can now start using modern bytecodes (indy) which the old version of ASM just didn’t support
+ there was a bug in the emission of certain static method invocations due to the old ASM not fully supporting 1.9 bytecode verification changes
@kenny Why are you trying to manually compile Clojure code and run it with java
? That seems like a very painful way to work.
@seancorfield Oh it is 🙂 I wanted to better understand what was going on behind the scenes.
@kenny I think one way if you want to learn what is going on is to just read the source of ‘lein run’ or ‘lein test’ task. Instead of going through this painful procedure.
@kenny Compiling Clojure is painful in all sorts of ways. We don't AOT anything at World Singles now. We still build (uber) JAR files for deployment tho' (from a mono-repo).
@seancorfield Cool. And you run the uberjar with clojure.main
instead?
Yes. java -jar path/to/my.jar -m my.app.entry
(we still highlight clojure.main
as the entry point)
It also has the benefit that if you want to explore the app interactively for any reason, you can run it without -m
and get a REPL that has all the dependencies and source directly available.
I have a unit test with clojure.test
that starts with instrument
and ends with unstrument
to mock out some function calls. However, it seems to sometimes call the underlying functions I’m mocking and accessing the database, which I’m trying to avoid. Any idea how to make sure there’s no race condition happening here?
that being said, I doubt there is a race condition there, my guess is the race condition is you are spinning up threads to do something in your test, and don't ensure dynamic extent of the thread is the same as the dynamic extent of the test
Hmm, ok.
I’m still figuring out the best way to get spec.test into our pipeline.
No, I'm adding the string "third" to the list ["first" "second"]. Let me try your approach.
Clojure 1.9.0
user=> (def state (atom {:task-list ["first" "second"]}))
#'user/state
user=> (swap! state update-in [:task-list] conj "third")
{:task-list ["first" "second" "third"]}
user=> @state
{:task-list ["first" "second" "third"]}
user=>
My bad, sorry about that 😉 This works indeed. Thanks a lot!! Clojure is sometimes a bit overwhelming to find elegant solutions
I was on the fence but I use it all the time
like, we had update-in
, it works fine, but someone decided to create a jira issue because they wanted a version that only worked for a single path segment, and then spend however many months to shepherd that change through and get it merged, and then it caused issues with different clojure libraries because it introduced a commonly used name in to clojure.core
so now, everytime someone writes code that uses update-in
and works just fine with a single segment, the first comment is someone going "but actually you should use update"
@hiredman assoc-in and update-in were slower I thought. update is perhaps a bit faster. Looking at impl now it isn’t a big difference though. Except update was implemented with more explicit arities
To me Clojure feels somewhat "hacky", like 'emacs lisp', coming from OO languages and having some little experience with Haskell and Scala. But I guess this is a more of an evolutionary approach.
I think it would be hard to reconcile the idea it is hacky with rhickey, but it is definitely coming from a very different place
if you haven't see "are we there yet?" from almost 10 years ago, it is still very good, and I think puts on display a lot of the thought that went in to clojure
Yeah, I've watched many talks he has given and my impression is that he is less likely inclined to the way academic groups would design a language. But I like that a lot, as for example Scala seems to artificial from time to time. And not to mention Java itself, which is very robust, but lacks innovation. Once again thanks for your help @hiredman!
this is a fun metaphor: https://gist.github.com/oakes/c82cd08821ce444be6bf
also fun is seeing how the Clojure compiler's Java is written: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L172-L190
Im looking for a way to get the full path to leaf nodes of a map of maps, so for example if I have {:a 1 :b {:c {:d 2}}}
it would return [[:a] [:b :c :d]]
e.g. the result would be vectors suitable to pass to get-in
to retrieve any individual value from the original map
suggestions on approach appreciated, don't need full solution
user=>
((fn map-paths [path m]
(if (map? m)
(for [[k v] m
i (map-paths (conj path k) v)]
i)
[[path m]]))
[]
{:a {:b 1
:c [3]}
:w {:x 1}})
([[:a :b] 1] [[:a :c] [3]] [[:w :x] 1])
user=>
thanks, more than I expected to receive
and to answer your question, in this case I want to convert an object structure to a java properties list