This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-16
Channels
- # 100-days-of-code (1)
- # announcements (1)
- # beginners (93)
- # boot (46)
- # cider (40)
- # cljdoc (4)
- # cljs-dev (7)
- # clojure (78)
- # clojure-conj (12)
- # clojure-dev (17)
- # clojure-italy (5)
- # clojure-nl (10)
- # clojure-spec (34)
- # clojure-uk (36)
- # clojurescript (56)
- # code-reviews (6)
- # core-async (31)
- # cursive (12)
- # datascript (9)
- # datomic (19)
- # devops (2)
- # editors (3)
- # emacs (6)
- # events (2)
- # figwheel (1)
- # figwheel-main (11)
- # fulcro (59)
- # graphql (10)
- # hyperfiddle (3)
- # keechma (5)
- # leiningen (26)
- # luminus (1)
- # nrepl (5)
- # re-frame (5)
- # reitit (10)
- # shadow-cljs (64)
- # spacemacs (29)
- # tools-deps (6)
- # uncomplicate (8)
- # vim (2)
- # yada (4)
How can I reload a NS in REPL?
I am trying to develop an app which dynamically loads namespaces specifies by a user. If I use REPL and namespace load fails because of a mistake, then rerunning (require '[my-ns :reload :verbose])
doesn't reload the namespace, running the code produces same error over and over again until I restart the REPL.
@roklenarcic I think it should be (require ['my-ns] :reload :verbose)
I'll try
@jkr.sw you were right, I was using reload wrong
thanks
An idiomatic question: Did you find useful to use records for domain objects in system instead of plain maps? E.g.: When a function receive a user object from an HTTP response it converts the response to User record like (map->User response)
instead of passing “just plain response” around.
Plain maps with namespaced keywords much more ideomatic than records, imho.
I think opinions differ here. Many people prefer plain maps though. The Clojure Applied book shows a usage of records. Here's an interesting discussion on this Slack:
* seancorfield @alexmiller On that subject... given the general advice re: maps / records is usually "use maps, and only switch to records if you need extra performance", how does that sit with using namespaced maps -- since those cannot easily be switched to records?
* alexmiller it complicates it :)
* alexmiller I mean if you have maps with namespaced keys, you can switch to records and change specs from :req to :req-un
* seancorfield Fair enough. The spread of namespaced maps does seem to reduce the attraction of using records further.
* alexmiller unfortunately, I agree. I seem to be in the minority, but I like records. :)
:thinking_face:
not really, I only find it useful if you are using polymorphism somewhere (i.e protocols)
Any spec-experts know the solution to this problem I posted a while back? https://clojurians.slack.com/archives/C03S1KBA2/p1539171271000100
Why not s/nonconforming? You seem to be excluding the thing that does what you want?
I might be remembering wrong, but s/nonconforming excludes all other kinds of conforming that you might end up wanting as well, right? That's what I was hoping to preserve!
Sorry if my simple example gave the impression that I didn't need to conform the rest either!
i figure if java requires always requires a main
then we always have to start a clojure program via -main
?
I think Alex has considered an arbitrary fn entry point before. A JIRA ticket might even exist
it would make it a little easier to keep alike fns in the same namespace. for example i have build-tools
which has a handful of useful scripts, but if i have to always expose -main
it’s a little more annoying to consume from the cli
you can invoke clojure myscript.clj
which has an arbitrary top-level call in it
$ cat foo.clj
(defn hi [] (println "hi"))
(hi)
$ clj foo.clj
hi
or you can combine -i and -e for similar effect
$ cat foo.clj
(defn hi [] (println "hi"))
$ clj -i foo.clj -e '(hi)'
hi
you can have multiple -i’s to load multiple files
Don't? 🙂
I started down that path several years ago. Tried to find a well-maintained Clojure library. Gave up. Forked one and got it running on an up-to-date version of Clojure but I couldn't get it to work satisfactorily. Ended up using Java interop and Java Axis libraries directly. Unpleasant but not as unpleasant as doing it in Java 😐
How do you name your transducer xforms? I am recently using more and more reusable xforms and I started wondering — any naming conventions to mark them as being different from a function?
@emccue last time i had to do that i used SoapUI to explore the api and to generate some template requests, filled out the requests with some simple mustache-like string templating... then clojure.data.xml to parse the responses - cheesy code, but effective
@isaac java's assert isn't a JVM level construct. It's a Java language construct. There's very little way for Clojure to "use it".
Java's assert simply checks a condition and throws an AssertionError if the condition fails. Clojure does the same thing.
my company is open sourcing our kafka lib soon, it uses spec with avro extensively, one of my coworkers will be presenting it at clojure/conj
but yeah, interop is good for a start
@noisesmith charles reese?
exactly the guy, he was the tech lead on my previous team, now he's on the architecture team
(our project was wildly successful when it went live, and was 100% a "consume from a bunch of kafka, and publish a bunch of kafka" thing)
this was pretty helpful - https://github.com/clojure-cookbook/clojure-cookbook/blob/master/04_local-io/4-14_read-write-clojure-data-structures.asciidoc
however - doing a read-string to convert string back to clojure data structure doesn't work well on java arrays -
I'd recommend using the transit library - it's easy to extend to any data type
arrays are mutable, so they are intentionally not printed readably
With immutable data, writing it out than reading it back is literally the same as using the original object. With something mutable, it's not.
hmm ... I guess that makes sense. With mutable data structure - it's printing more the meta data - than the data
transit is way faster than EDN, but last I checked Transit was also marked as "not done" and "may change in the future, don't use this for at-rest data".
That being said, the format hasn't changed in the past 4 years
also, compared to other relatively fast alternatives, it supports all the core clojure data types and accepts first class reader and writer config at call site rather than as a global config
agreed. If you need more performance you can also use fressian which is what Datomic uses to store data. It's clojure-only, but very stable, very fast, and it's a binary format, so it's quite compact: https://github.com/clojure/data.fressian
fressian + json encoding = transit (for the most part)
@tbaldridge What the performance diff between fastxlm jackson
and transit
?
Thank you for the pointers - I've used transit quite often - particularly on clojurescript side - will also check out fressian
Well transit is the only one with caching/dedupping so in many cases it will be the fastest. I have yet to see XML ever be faster than JSON
if you have a keyword reported over and over, transit will replace the keyword with ^1
, ^2
etc.
That means a savings in space, and also a performance savings on both ends as the same value can be plugged in instead of reading/interning the keyword every time.
Hi Clojurians. Is there a way to take a Clojure collection like
[{:k1 "v1", :k2 "v2"} {:k1 "v3", :k2 "v4"}]
and return it as the JSON equivalent
[{"k1" : "v1", "k2" : "v2"}, {"k1" : "v3", "k2" : "v4"}]
I used Cheshire and it's generate-string
function, but it results in a single string with escaped quotes, e.g.
"[{\"k1\":\"v1\",\"k2\":\"v2\"},{\"k1\":\"v3\",\"k2\":\"v4\"}]"
and I tried parse-string
on that, but it results in something like this without the colons:
[{"k1" "v1", "k2" "v2"}, {"k1" "v3", "k2" "v4"}]
"[{\"k1\":\"v1\",\"k2\":\"v2\"},{\"k1\":\"v3\",\"k2\":\"v4\"}]" is what it looks like printed via prn
So if I wrote that to a file from Clojure, would it have the non-escaped version?
I'm basically trying to randomly generate some data which will be used within an api from a json formatted feed (i.e. from a json file)
if you used pr anywhere it will have the escaped parts because pr outputs things that can be read back in, so inside strings " needs to be escaped, etc
if you do something like (println (generate-string {:a 1}))
you will get json without the escaping
Perfect, that did the trick! Thank you @hiredman 🙂