meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
dominicm 2020-05-19T15:00:24.244500Z

Has anyone made a try+ meander yet?

noprompt 2020-05-19T15:51:51.244900Z

try+?

dominicm 2020-05-19T16:09:15.245Z

Like slingshot.

dominicm 2020-05-19T16:09:33.245100Z

https://github.com/scgilardi/slingshot/

dominicm 2020-05-19T16:11:23.245200Z

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"}))

1
dominicm 2020-05-19T17:07:14.245400Z

What's the "match anything" or what's the "else" for m/match?

dominicm 2020-05-19T17:09:04.246500Z

Quite enjoying this, because I can write naively and optimize the macro output

🙂 1
jimmy 2020-05-19T17:16:39.246700Z

Match anything is _

jimmy 2020-05-19T17:17:07.247300Z

Or if you want to capture it, you can just do any any ?logic_variable.

noprompt 2020-05-19T17:34:18.248200Z

LOL I need more messages like “Write better SQL, Idiot” in my life.

noprompt 2020-05-19T17:35:29.249300Z

I can’t remember which command it is/was but it would complain about a “Cowardly attempt to…”

noprompt 2020-05-19T17:35:55.249600Z

Just calling me out.

timothypratley 2020-05-19T18:52:17.249700Z

For me its Cowardly refusing to create an empty archive from tar 🙂

dominicm 2020-05-19T19:02:36.249900Z

Hmm.. (if (= (System/getenv "USER") "noprompt") (throw ...))...

noprompt 2020-05-19T19:17:41.250Z

HAHAHA! Yeah! Thats the one! 😂

noprompt 2020-05-19T19:18:07.250200Z

For some reason I remembered it as calling me the coward. 😛

noprompt 2020-05-19T19:18:58.251Z

Okay… I’m slowly getting my head out of the vacation clouds.

dominicm 2020-05-19T19:53:00.251100Z

It's 70loc, but I have it...

dominicm 2020-05-19T19:53:28.251200Z

Something that's a little tricky is the fact you have to "jump" priorities a little bit.

dominicm 2020-05-19T19:53:42.251300Z

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")))

noprompt 2020-05-19T20:05:11.251900Z

Pulled it off with rewrite?

dominicm 2020-05-19T20:06:34.252Z

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 ;)

dominicm 2020-05-19T20:15:01.252100Z

https://git.sr.ht/~severeoverfl0w/workshop.try.meander

dominicm 2020-05-19T20:15:36.252200Z

I'll give it a real name later, but it seems like a neat idea & works in the REPL.

noprompt 2020-05-19T20:18:15.252400Z

Nice. 🙂

noprompt 2020-05-19T20:18:23.252700Z

I kinda wanna mess around with this.

dominicm 2020-05-19T20:19:16.253800Z

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.

dominicm 2020-05-19T20:28:19.256800Z

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