This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-04
Channels
- # adventofcode (171)
- # beginners (160)
- # boot (13)
- # chestnut (2)
- # cider (6)
- # cljs-dev (15)
- # cljsjs (35)
- # cljsrn (1)
- # clojure (139)
- # clojure-argentina (3)
- # clojure-brasil (1)
- # clojure-greece (31)
- # clojure-italy (5)
- # clojure-russia (5)
- # clojure-spec (18)
- # clojure-uk (11)
- # clojurescript (42)
- # clojurex (6)
- # core-async (12)
- # cursive (14)
- # dirac (13)
- # emacs (13)
- # events (1)
- # fulcro (46)
- # graphql (7)
- # leiningen (10)
- # lumo (3)
- # mount (31)
- # off-topic (20)
- # onyx (30)
- # perun (4)
- # planck (47)
- # re-frame (28)
- # reagent (14)
- # ring (5)
- # shadow-cljs (3)
- # spacemacs (7)
- # specter (13)
- # timbre (3)
- # unrepl (65)
- # yada (8)
except those pre/post conditions often come with a performance hit
Sure, I turn them off in production in clj and cljs - (set! *assert* false)
/ :elide-asserts true
respectively
@bravilogy You need (-> (client/get uri {:headers {"apisign" sig} :as :json}) :body :result)
-- You are trying to get the :result
element out of the :body
of the client/get
response.
The conversion to text happens when Ring is rendering the result.
Random brain firing - is there a way to capture the current function's actual object instance? There are some recursion patterns which would be a lot easier to implement if you could just recursively pass the current function with its closure and all.
@arrdem I'm probably misunderstanding, but does this help?
+user=> (defn foo [] foo)
#'user/foo
+user=> (= (foo) foo)
true
does it need to be a way to automatically capture the current fn where you can't know the name (or even work in a case where a name is impossible like comp or partial) ?
user=> (def a (fn [x] (fn foo [] (println x) foo)))
#'user/a
user=> ((a 1))
1
#object[user$a$foo__135 0x542e560f "[email protected]"]
user=> (((a 1)))
1
1
#object[user$a$foo__135 0x1d730606 "[email protected]"]
user=>
oh no I have become a tool of evil
Hi, can anyone suggest me some small learning project which would give me some idea about handling concurrency in clojure. Something which can be finished in a week.
A small 'simulation' program where you model a world, with interacting 'actors' (not in the Erlang sense) of some sort. - A toy factory, where many workers work independently and collaborate - An aquarium, where creatures eat each other / survive / reproduce - etc Those are particularly suited for concurrency. For parallelism, try doing either a CPU-bound (math? parsing?) or IO bound (web crawling?) workload as efficiently as possible
@U45T93RA6 thanks for the reply, this seems interesting.
thanks that would be great help, I have done some projects like parser & interpreter in clojure but nothing related to concurrency
if you feel like taking a look: https://github.com/sumitkumar15/supergit https://github.com/sumitkumar15/relisp ๐
I'm writing a macro in a *.cljc file. Is there a way to make it expand to different things depending on whether it is being expanded in CLJ or CLJS code ?
@qqq You may find this helpful: http://blog.fikesfarm.com/posts/2015-06-19-portable-macro-musing.html
Long story short is its a bit of a pain
actually, how is it painful?
(defmacro str->int [s]
#?(:clj (Integer/parseInt s)
:cljs (js/parseInt s)))
looks straightforward -- and I was already doing this, without even realizing itSure, I turn them off in production in clj and cljs - (set! *assert* false)
/ :elide-asserts true
respectively
@qqq I think you example macro is not right, itโs evaluating the expression at compile-time.
Agreed
also, you need to know what you are emitting from the macro: clj or cljs. There are hacks to get this info. And a awesome lib hiding the details: https://github.com/cgrand/macrovich
Good to know about this!
(defn select-rename [m ks]
(into {}
(for [[old-k new-k] ks]
[new-k (get m old-k)])))
(select-rename
{:a 20
:b 30
:c 40} [[:a :foo] [:c :bar]])
Is there a builtin for this ?Also note that you can implement this without an intermedia seq by using a transducer: (into {} (map (fn [[old new]] ...)) ks)
@the-kenny: I agree that unnecessary intermedaite seqs are bad. Can you clarify where my code is generating it ?
(= 2 (+ 1 1))
(comment
true)
(= (int-array [2])
(int-array [(+ 1 1)]))
(comment
false)
I'm okay with the int-array returning false. My question is: is there a way I can overload/hack equality so it returns true if they're elementwise equal ?What is the best way to run all unit tests (assuming that they are in different namespaces) in a project, without requiring them first, from the repl?
@stuartsierra any idea ? โ๏ธ
Count result of a transduction, which one is preferable?
;; 1
(count
(sequence (map identity)
[1 2 3]))
;; vs
;; 2
(transduce (map (constantly 1))
+
[1 2 3])
@borkdude the first one makes more sense to me. I think you could use eduction
in place of sequence
if this is the exact usage, as it will be faster.
In that case, use sequence
if it's not fast enough, benchmark the transduce (but I wouldn't expect that to be faster, it's potentially slower!)
last but not least, use eduction
with a fold
to parallelise the count
, if your resulting collection will be large enough. Also benchmark this approach.
@dominicm This is just #adventofcode related, so I guess readability is slightly more important. Iโll go with sequence.
sorry for the crosspost - has anyone seen this before? https://clojurians.slack.com/archives/C075TNSSC/p1512387863000190
@tristram Try https://confluence.atlassian.com/jira/connecting-to-ssl-services-117455.html (see Resolution section)
it tells how to get certificate for your url and to import into Java cert store to trust it
@tristram those instructions are to be done at client computer
i. e. at your work machine
it's not required for it to be a server
to successfully run Portecle app, to get http://github.com certificate by it and to import that certificate to local cert store
well, I fixed it by uninstalling and reinstalling openjdk-8-jdk
constantly throughout the day
FWIW, the last line I ran, from having no jdk installed, was
sudo apt install openjdk-8-jdk
I expect 1.9.0-RC2 is exactly what 1.9.0 will be :)
(let [a (if editing? edit-a (-> data :foo :bar :a))
b (if editing? edit-b (-> data :quux :b format-b-for-display))
c (if editing? edit-c (-> data :otherkey :c))]
[1 2 a b c 3 4])
Can I write this more concise without repeating (if editing?)
so often?Using vectors and destructuring perhaps?
(let [[a b c] (if editing?
[edit-a edit-b edit-c]
[(-> data :foo :bar :a) (-> data :quux :b format-b-for-display) (-> data :otherkey :c)])]
[1 2 a b c 3 4])
@matan Re: stability -- we've had all the 1.9 Alpha and Beta builds in production for ages. We have RC1 in production right now with RC2 going to production at 2pm Pacific today.
to use either float? or double? here youโd need to do some conversion first. clojure.edn/read-string? will never return floats, only doubles
if what you want is to know if a string is a valid floating point number, I think the best option is (try (Double/parseDouble %) (catch Exception _))
- itโs ugly but it works - either a number or nil comes out
@seancorfield sounds good. but did you have a specific agenda in chasing the bleeding edge like that? I mean 1.8 was good and stable. care to clarify the motivations for this chase? I just can't help but wonder as most people won't go that far (or fast :) I guess..
We've pretty much always used Alphas in production as they become available for over six years: because we want access to the latest features. We're using clojure.spec
heavily in production, for example.
@matan there's really not a reason not to. Clojure alpha/beta versions very rarely break existing features. Most of the time I upgrade, run the test suite, and if those tests pass we're good.
Last time I remember Clojure "breaking" something critical was when they changed the hashing algorithm back in 1.6. But even that wasn't Clojure's fault since order of items in sets is undefined (hence why they are unordered sets). So that was a bit painful to fix, but it was considered a code cleanup since the problem was in the code that used Clojure.
But I can't even think of a time I've had my correct code break from a Clojure upgrade.
i wasn't around back then so i don't know but i thought i remember hearing about that
well yeah, I'm not going that far back. and I joined Clojure right when 1.3 was released ๐
That was back in 2011, lol
well there's a good answer then. there haven't been breaking changes in an upgrade for 6 years or so
There are times where there were perhaps legitimate questions whether a change in a release was breaking or not, such as the hash change in 1.6 also leading to hash inconsistency between Java sets and Clojure sets that were clojure.core/= before and after, but no longer had the same hash any more.
Which then causes sets or maps containing those things not to be clojure.core/= any more.
Such questions usually lead to refinements in the definition of what was promised, and what wasn't.
adding validation to the ns macro which subsequently stopped (ns foo (use bar)) being acceptable is another one of those things
no one said it would work, but it did, and now it doesn't. given the low number of people affected and how easy it was to fix I'm glad they went with locking it down though
Hmmm,
> (println '(and "foo"))
(and foo)
I would expect that to print (and "foo")
. Does anyone know why it doesn't? Is there a way to include the quotes?We've pretty much always used Alphas in production as they become available for over six years: because we want access to the latest features. We're using clojure.spec
heavily in production, for example.
ISTR 1.4 "broke" some stuff around numeric overflow / representation? (didn't affect us) and 1.5.0 had a memory leak (fixed in 1.5.1 -- we were spared that as we were on a pre-release of 1.5 in production at the time, before the leak was introduced, and we went straight to 1.5.1 because of our release schedules at the time). And the hash code change in 1.6 didn't bite us either (I'm still not clear on how widespread that breakage was?).
We started with Clojure 1.3 (Alpha 7 or 8 in production) because we wanted to skip ahead of the big 1.2 -> 1.3 Contrib split and the AOT compatibility issues around that. It's also how I ended up maintaining clojure.java.jdbc
-- because clojure.contrib.sql
needed a maintainer to bring it across the 1.2/1.3 divide ๐
We test our apps against Clojure's master SNAPSHOT as well as whatever version we're going to production with so we get a heads up of any breakage.
@tbaldridge @seancorfield thanks for the perspectives and explanation โ I sure learned something new
As someone who does not maintain a clojure core library, I might be a bit more conservative myself ๐ but testing against Clojure's master snapshot sure sounds nice (especially if it doesn't break the test suite very often)
One of Clojure's strengths, in my opinion, is how stable it has been across versions. The Clojure/core team are very serious about accretion rather than breakage ๐
Something else โ roughly one week ago I asked about writing code for stream-processing of data, which gave rise to a short discussion suggesting that although collections are sufficiently lazy (only up to 32 items may be realized under the covers at any point in time), transducers should be strictly preferred for a streaming application. In streaming I mean, mainly, processing an input file using only a constant memory footprint, rather than consuming the entire (potentially humongous) file into memory and such. Then also processing the stream forward through whatever few processing steps, in a similar way, for the same reason. Do folks here agree to that suggestion, about preferring transducers over plain lazy collections?
lazy collections and transducers arenโt mutually exclusive
transducers are a good option for describing and composing the individual steps
they also are useful for streaming because they donโt care about the source or the sink
in general, for streaming processing, you are going to be working with folds (a tree shaped process, the degenerate shape of which is a linear reduce)
as far as processing data with constant memory requirements, you can use lazy sequences, but there are other good options as well
once you are working folds, using transducers and transduce is pretty much a no brainer
there are also a lot of stream processing libraries to choose from that help provide a good story for how to put everything together
when you are using a fold like reduce (or transduce) you also get a pretty clear scope for managing resources (like closing db connections, or files, or whatever) which lazy-seqs don't really give you
(interleave @smith.adriane @hiredman) ๐
@matan I prefer transducers in this case simply beacause it's really hard not to hold onto the head of a seq with lazy seqs. And with transducers its pretty much impossible to shoot yourself in the foot this way.
I've built too many systems that work fine until you get about 2GB of data through them then they fall over due to some sort of lazy-seq related memory "leak"
Hello Everyone. Are there any good resources to learn Clojure quickly and efficiently?
If you don't mind paying some $, Clojure Programming is a good book: http://shop.oreilly.com/product/0636920013754.do There are other fine books to learn from, also.
@faraj.9798 I will also add Clojure for the Brave and true https://www.braveclojure.com/ If you are looking for raw time to workflow, then brave clojure has the advantage there IMHO. If you want a more in depth resource, then the O'Reilly book is always a really safe bet. It just depends on where your priorities are.
Or Living Clojure by Carin Meier, or Programming Clojure 3rd Edition... ๐
Clojure Programming is good for the basics but a little outdated now (it targets Clojure 1.5 I think?).
Nope, 1.4 (examples work on 1.3 and 1.4). So I'd be cautious to recommend Clojure Programming at this point (although I love it as an all-round introduction to the language and some common libraries -- it's clojure.java.jdbc
section is outdated, due to lots of improvements in that library... I'm not sure it's example even work with recent clojure.java.jdbc
versions).
@faraj.9798 If you're new to Clojure, you'll find the folks in the #beginners channel are super helpful.
I'm interviewing at a company that uses Clojure and React. I'm comfortable with React, just need to increase skills with Clojure.
Cool. Good luck with the interview! Are they using Clojure on the server or ClojureScript with React on the client?
I think Clojure on the server? They never mentioned ClojureScript.
'k ... we're React on the front, Clojure on the back too ... it's a good combination.
Where do you work....? Haha
@seancorfield Is that React without clojurescript? If so, what were the motivators for that decision?
Thanks everyone for your help.