This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-19
Channels
- # announcements (12)
- # aws (17)
- # babashka (6)
- # beginners (40)
- # cider (14)
- # cljs-dev (14)
- # cljsrn (8)
- # clojure (110)
- # clojure-europe (46)
- # clojure-italy (1)
- # clojure-nl (4)
- # clojure-spec (14)
- # clojure-sweden (3)
- # clojure-uk (29)
- # clojurescript (52)
- # conjure (68)
- # cursive (33)
- # datomic (9)
- # figwheel-main (11)
- # fulcro (97)
- # ghostwheel (1)
- # graalvm (2)
- # helix (53)
- # hoplon (13)
- # joker (6)
- # kaocha (1)
- # leiningen (2)
- # meander (28)
- # mid-cities-meetup (1)
- # observability (1)
- # off-topic (112)
- # pathom (6)
- # pedestal (3)
- # re-frame (16)
- # reagent (16)
- # reitit (2)
- # shadow-cljs (27)
- # spacemacs (2)
- # sql (26)
- # testing (3)
- # utah-clojurians (3)
- # vim (2)
- # xtdb (32)
I was thinking this would be pretty dope:
(try+
(add-user! user)
(catch {:type ::data.user/user-exists :id ?user-id}
{:message (format "Oh no, %s user exists!" ?user-id)})
(catch {::anom/category :forbidden}
{:message "GO AWAY"})
(catch SQLException e
{:message "Write better SQL, Idiot"}))
Match anything is _
Or if you want to capture it, you can just do any any ?logic_variable
.
I can’t remember which command it is/was but it would complain about a “Cowardly attempt to…”
For me its Cowardly refusing to create an empty archive from tar 🙂
Something that's a little tricky is the fact you have to "jump" priorities a little bit.
This is fully functional though:
(try+
(throw (ex-info "Invalid" {:type :pity :reason "???"}))
(read (clojure.lang.LineNumberingPushbackReader. (java.io.StringReader. ")")))
(throw (ex-info "Invalid" {:type :invalid :reason "I pity the fool"}))
(/ 1 0)
(catch ArithmeticException _
::infinity-stones)
(catch clojure.lang.LispReader$ReaderException {:clojure.error/line ?line}
(println "Check line" ?line))
(catch {:type :invalid :reason ?reason}
(prn ?reason)
nil)
(catch {:type :pity :reason ?reason}
(println "PITYPITYPITY" ?reason)
nil)
(catch clojure.lang.ExceptionInfo e
(prn (ex-data e)))
(finally (println "Cleaning up")))
Didn't need it at all in the end. Rewrite made it more complicated tbh, because you have to look ahead. I'm sure you'll show me the one-liner in a sec though ;)
Do it. I consider the idea primitive, so if you want to build on top of it, go to town. I don't feel any particular ownership.
Meander has a great api for simple cases, like matching a few keys in a map on value. It makes this kind of lightweight thing really nice. The only real catch is that I need to specify that you need to use epsilon in order to interact with it, as it's incompatible with the other versions. But that's not a big deal really, eventually it'll be stable and I can "meander" rather than caveating