This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-02
Channels
- # beginners (26)
- # bitcoin (1)
- # boot (9)
- # boot-dev (5)
- # cider (26)
- # cljs-dev (1)
- # clojure (190)
- # clojure-finland (1)
- # clojure-italy (42)
- # clojure-nl (20)
- # clojure-russia (3)
- # clojure-sanfrancisco (1)
- # clojure-serbia (1)
- # clojure-spec (50)
- # clojure-uk (16)
- # clojurescript (62)
- # core-async (4)
- # cryogen (1)
- # cursive (6)
- # datascript (1)
- # datomic (36)
- # duct (6)
- # editors (6)
- # emacs (14)
- # graphql (3)
- # leiningen (30)
- # off-topic (21)
- # om (7)
- # parinfer (13)
- # portkey (56)
- # re-frame (2)
- # reagent (2)
- # shadow-cljs (58)
- # vim (1)
- # yada (3)
@noisesmith any examples in the wild of how that would like? I mean a closure that maintains mutable state and exposes an API...
a rough skeleton is (defn make-connection [config] (let [state (atom nil)] (reify connection (connect [opts] (reset! state (do-connect (merge config opts))) (connection [] @state) ...)))
probably make connect return nil so people don't try to use the value it returns instead of the wrapper, use try/catch in each method to recover and reconnect (or fail in a defined way) etc.
sorry, no really good example in an open source project I can think of right now
right, exactly
in clojure in order to implement proper methods you want a protocol or interface
oh also that usage of reset! and even putting the state in an atom are both actually bad - atoms are made for immutable data and can misbehave badly when they contain mutable things which means you need to mess with locks most likely D:
Hi guys. Would it be wise to dive into Clojure without any actual Java/JVM knowledge? I have only C++ & Python on my back, and almost completed SICP, should I at least read some book on Java before going full Clojure?
Hi, I recently started programming in Clojure and I come from an R/Python background, but no Java whatsoever. I didn't have many issues. Lately I'm starting to understand better the JVM, Java and compilation options because I'm starting to use Clojure at work and I would like it to be flawless (as much as possible :)
Reading a book on java before going to Clojure isn’t needed. When you start thinking about running it in production it would be useful to know some more about the jvm, like how to manage the memory, and maybe how to monitor.
Thanks for your advice you guys! @UAE4G28HX Glad to hear this path is possible 🙂
Hi, I recently started programming in Clojure and I come from an R/Python background, but no Java whatsoever. I didn't have many issues. Lately I'm starting to understand better the JVM, Java and compilation options because I'm starting to use Clojure at work and I would like it to be flawless (as much as possible :)
Is it safe, in terms of sorting/order, to do (zipmap (map :id xs) xs)
? Or is there potential for the id to actually be incorrect for a given x
?
@dadair I can't think of any collection type for xs that you would reasonably be using that would change order when used twice
I believe it is safe, since (keys m)
and (vals m)
are guaranteed to produce the same order, as I recall (for the identical m
).
but keys and vals don't come into play here
Another option to consider for that, by the way, is (into {} (map (juxt :id identity) xs))
yes, I like the juxt version better personally
@noisesmith No, I'm just applying an extension of the logic behind that guarantee (about keys
/`vals`).
oh, I see
It is safe
Everything is based on seq order, which is stable
BTW @dadair The fastest solution (for large sequences of maps) seems to be (into {} (map (juxt :id identity)) xs)
-- note the parens here: it's using the transducer version.