This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-01
Channels
- # adventofcode (11)
- # aws (8)
- # beginners (70)
- # boot (2)
- # cider (9)
- # cljs-dev (29)
- # cljsrn (2)
- # clojure (67)
- # clojure-android (2)
- # clojure-dusseldorf (5)
- # clojure-greece (12)
- # clojure-italy (4)
- # clojure-nl (3)
- # clojure-poland (3)
- # clojure-russia (5)
- # clojure-spec (80)
- # clojure-uk (9)
- # clojurescript (73)
- # core-async (17)
- # cursive (1)
- # data-science (5)
- # datomic (29)
- # emacs (5)
- # fulcro (257)
- # graphql (2)
- # hoplon (2)
- # jobs (2)
- # klipse (3)
- # leiningen (9)
- # lumo (4)
- # nyc (1)
- # off-topic (48)
- # om (7)
- # other-languages (11)
- # pedestal (4)
- # re-frame (18)
- # remote-jobs (1)
- # rum (10)
- # shadow-cljs (5)
- # spacemacs (20)
- # sql (5)
- # test-check (44)
- # unrepl (8)
- # yada (9)
hello! I'm confused about project dependencies when linking to clojure from another JVM language; I've articled my problem/question fully here: https://stackoverflow.com/questions/47586889/handling-clojure-project-dependencies-when-dynamically-linking-to-clojure-runtim. If anyone could help that would be greatly appreciated 😄
@dadair I have similar setup for two projects. I have Clojure code compiled as überjar, intended to be used as a library from Java (and some Java classes calling the Clojure code - :gen-class won't create javadoc for classes/methods and my colleagues would be upset 🙂 ). I ended up with embedding nREPL in the project. I copied code from this library: https://github.com/jarohen/embed-nrepl . From Java code I call the Clojure method to start repl during application start. Then I can connect to that from emacs.
I'll second that. For a long time -- as we introduced Clojure into our stack -- we used the "Java API" to call Clojure from our legacy application and we started a REPL server inside that code which we could connect to from Emacs or the command line and have our regular fast-feedback Clojure workflow.
so to use clojure in a legacy codebase with coworkers who don't want to use java, you are: 1. compiling *.clj iknto uberjar 2. when the uberjar is called from java, firing up a nrepl 3. so now you have a clojure repl into your legacy java app (that still "starts from java") ?
One thing I'll observe is that we deliberately did not create an uberjar and deploy things that way -- we decided to deploy as source and put the src
folder on the classpath of the legacy application (along with any Clojure libraries we needed). This meant we could modify source if needed and require
:reload
to pick up changes (I'll say that we rarely do this now, but it was common when we first started embedding Clojure).
The progression for us was that we started using Clojure as a small, isolated "library language" for low-level stuff and it gradually expanded until it became our primary language. Now we do all new development in Clojure and our legacy systems are shrinking as we replace functionality with pure Clojure microservices and applications.
What is the best way to type hint an Object[]
array in Clojure? I've seen this method #^"[Ljava.lang.Object;"
here (http://disq.us/p/1buoakl), but I'm not sure it's officially supported.
It’s supported
@val_waeselynck Check out to-array
source.
@val_waeselynck ^objects works as well
@U088T6UDC thx! weird that it's not in the official docs
That will not work on vars by the way, only in signatures
What’s the rationale behind nthrest
? Noticed it for the first time today. What about (drop n ...)
wrapped in doall
if you need it strict?
It seems to be born out of a refactor of partition
:
https://github.com/clojure/clojure/blame/b98ba848d04867c5542d50e46429d9c1f2472719/src/clj/clojure/core.clj#L3166
(cc @mfikes)
Interestingly, they both seem to have a recur
pattern that is eagerly done to consume the beginning of the sequence.
so the difference is nthrest
skips n
immediately and drop
only when the sequence is consumed
hmm yeah, so (doall (drop ...))
would consume everything in the dots too, while nthrest
leaves that to the consumer of the seq
You do have an interesting question regarding rationale, especially given that nthrest
wasn't added until 1.3
I guess not, because that was the impl before: https://github.com/clojure/clojure/commit/82c72549f455e68a314593c67436e7a14c64a931
@borkdude If you are curious as to my rationale for using nthrest
: It was simply that I had used rest
(instead of (drop 1 ...)
, so when I needed to revise the code to drop more items, I reached for nthrest
without thinking about it too deeply. I certainly wasn't thinking about laziness, whether to employ transducers, or any such deeper analysis.
Yeah, when I saw your code I started thinking about transducers. It lends itself well for it. But whatever, that’s not better or worse, just different and maybe overthinking a puzzle 🙂
FWIW, I think your final solution using drop
is the cleanest, easiest to read, especially given that the revised code needed to drop more than 1 item.
There is also an argument that some functions are a bit esoteric (and perhaps should be avoided). drop
is used 50 times more frequently than nthrest
in the data in http://www.lispcast.com/100-most-used-clojure-expressions
My favorite example Var in that category is when-first
. It is hard to justify using when-first
given that it never became part of the "idiom".
Indeed, that's the problem with using Vars like that. It is like using a "dictionary word" in conversation, where the other participants in the conversation get stuck on what you just said.
Ah, @alexmiller replied: it’s probably about holding the head
or simply avoiding calling first on anything for cases where that realizes things
How would I write this more concisely? (let [d {:a [{:b 1 :deleteme "foo"}]} f #(dissoc % :deleteme)] (update-in d [:a] #(mapv f %)))
If you are directly indexing :a
you might not mind numerically indexing its array using medley's dissoc-in
:
(let [d {:a [{:b 1 :deleteme "foo"}]}]
(dissoc-in d [:a 0 :deleteme]))
But if you have more than one element in :a
I would just inline the lambda instead and use update as bork suggests:
(let [d {:a [{:b 1 :deleteme "foo"}]}]
(update d :a (fn [m] (mapv #(dissoc % :deleteme) m))))
@mbertheau with specter: (setval [:a ALL :deleteme] NONE data)
Anyone here familiar with a javalib which compresses animated gifs, similiar to what Guetzli does to jpgs?
I don't know of anything, but if there is a C library that does what you need, it's straightforward to wrap C, and pretty pleasant using JNR-FFI
What do you do in clojure spec to generate sample (gen/sample (s/gen ::foo))
with unique value like code
. Do you make own function for code generation or is some simpler way?
you can use s/with-gen
to supply a custom generator when you define a spec
or supply an override generator function when a spec is used in places like s/exercise, stest/instrument, etc
yes, i was thinking about s/with-gen
. Not sure what you mean by override generator. Probably i don’t know about something 🙂
functions like s/exercise take a map of spec name to generator functions that can be used to override the generator for a spec just in the context of that call
clojure
user=> (s/def ::i int?)
:user/i
user=> (s/exercise ::i)
([0 0] [-1 -1] [1 1] [-1 -1] [-6 -6] [-6 -6] [-4 -4] [2 2] [-2 -2] [-56 -56])
user=> (s/exercise ::i 10 {::i (fn [] (s/gen #{5 10}))})
([5 5] [5 5] [10 10] [5 5] [5 5] [10 10] [10 10] [5 5] [5 5] [5 5])
the docs have been out of date for a very long time but I refreshed them last week
In Stuart Halloway's talk Simplicity Ain't easy, at the end he mentioned that there is some interesting discussion about design foundations other than simplicity. I can't seem to find any more information on it. Does anybody know of any discussion on that?
@radomski the three ones from Rich and Stu are power, focus, and simplicity
I think Stu has done talks on two of those (see also https://www.youtube.com/watch?v=KZ8u_sWT9Ls )
@alexmiller Thanks much!
Maybe some day he will complete the trilogy and then we can get into the prequels
just wait, he’ll use CGI to add realistic concrete inheritence when he re-releases the original
#rich_shot_first