This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-08
Channels
- # beginners (92)
- # boot (2)
- # cljsrn (6)
- # clojure (33)
- # clojure-austin (1)
- # clojure-dev (18)
- # clojure-spec (7)
- # clojure-uk (2)
- # clojurescript (35)
- # cursive (13)
- # data-science (3)
- # datomic (1)
- # defnpodcast (1)
- # figwheel (1)
- # fulcro (27)
- # instaparse (1)
- # java (2)
- # leiningen (8)
- # off-topic (5)
- # onyx (1)
- # portkey (2)
- # re-frame (9)
- # reagent (2)
- # ring-swagger (1)
- # shadow-cljs (136)
- # test-check (3)
- # tools-deps (29)
What is a good name for the foo
function below?
(defn foo [f ks]
(into {} (for [k ks] [k (f k)])))
(foo #(* % %) (range 3))
(comment
{0 0, 1 1, 2 4})
the best name I have so far is (k->v)->ks->map<k,v> but that is not a valid clojure symbol name
I think text obfuscated the sarcasm in suggesting (k->v)->ks->map<k,v>
-- I'd really prefer english words to type sigs š
It is a map that represents a partial version of a function.
I'd call it memo-map.
I just ran into clojure.core.match` and am in love. Is it bad to do things Elixir/Erlang style in clojure? Like
(if (... some validation ...)
[:ok (response :body)]
[:error (response :error-text)]))))
you can find Rich's thoughts on pattern matching here: https://gist.github.com/rgdelato/3d7b6ecbcb7e9b86335ded905667feb8#why-no-pattern-matching and also in this talk: https://www.youtube.com/watch?v=2V1FtfBDsLU
A lot of Rich's critiques are feel are stronger against typing systems when used with pattern matching. At run time, the parts of a OCaml type aren't named. That's to say you can't reflect on X and find out what parts X is made up of. I think a pattern matcher in the spirit of Clojure's values could be quite nice. Something like spec's keys or de-structuring:
(match x
{:shape/width w :shape/h h} (* w h)
{:shape/radius r} (* PI (* r r)))
But most pattern matching just devolves down to matching on vectors, tuples or tagged unions, which IMO is quite ugly.Returning tuples of tag and data is fine
For example clojure.spec s/conform also does that
Usually you dont need core match to dispatch them
For errors, when not explicit matching of a [:error e] / [:ok val]
pair like in Elixir/Erlang, or having multi returns like in Go, what is the idiomatic way to handle errors explicitly in Clojure?
also thinking about clojurescript where try/catch is a bit more tricky because of the lack of strong types
looking at it, core.match looks to be exactly what I wanted in Clojure for all these cases
@U0CJNMS5P If you return either {:ok val}
or {:error e}
then you can do
(let [{:keys [ok error]} (some-thing)]
(if ok
(process ok)
(handle error)))
or if you don't care about the error at all (if-let [result (:ok (some-thing))]
(process result)
(something-failed))
(although you can't return false
/ nil
that way -- you'd need to swap the test over to error
instead and use the first approach)
(let [{:keys [ok error]} (some-thing)]
(if error
(handle error)
(process ok)))
Though I barely see these patterns in clojure code so Iām wondering on one side why not, and what other ways to handle errors are more commonly used
Exceptions.
https://youtu.be/ZQkIWWTygio I really recommend this talk. I've personally found the tagged variant pattern to be superior for the reasons jneen talks about if you have appropriate tooling around it. http://github.com/arrdem/guten-tag was my take at that.
the internals of http://conj.io are mostly written in various variant patterns.
Anyone have a minimal prepl example?
For errors, when not explicit matching of a [:error e] / [:ok val]
pair like in Elixir/Erlang, or having multi returns like in Go, what is the idiomatic way to handle errors explicitly in Clojure?