Fork me on GitHub
#babashka
<
2020-02-26
>
sogaiu06:02:55

is it correct that there is no support for re-matcher?

borkdude08:02:01

@sogaiu if that mapping is missing in sci, feel free to make a PR

sogaiu08:02:22

thanks, i'll take a look

borkdude08:02:48

I'll quickly add it

sogaiu08:02:57

ah i'm working on it

sogaiu08:02:08

also re-groups

borkdude08:02:27

added re-matcher.. ah ok. feel free to PR re-groups ๐Ÿ™‚

sogaiu08:02:38

ok. btw, clj-kondo doesn't seem to be happy about re-matcher and re-groups

borkdude08:02:55

are you in a .cljc file?

sogaiu08:02:17

lol, i should have guessed ๐Ÿ™‚

sogaiu09:02:34

thanks!

$ ./bb
Babashka v0.0.74-SNAPSHOT REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (doc re-groups)
-------------------------
clojure.core/re-groups
([m])
  Returns the groups from the most recent match/find. If there are no
  nested groups, returns a string of the entire match. If there are
  nested groups, returns a vector of the groups, the first element
  being the entire match.
nil

๐Ÿ™‚ 4
sogaiu09:02:19

here's some more useful evidence of things functioning (from clojuredocs):

$ bb
Babashka v0.0.74-SNAPSHOT REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (def phone-number "")
#'user/phone-number
user=> (def matcher (re-matcher #"((\d+)-(\d+))" phone-number))
#'user/matcher
user=> (re-find matcher)
["672-345" "672-345" "672" "345"]
user=> (re-groups matcher)
["672-345" "672-345" "672" "345"]

borkdude09:02:52

Great - thanks for testing ๐Ÿ™‚

โœ… 4
borkdude11:02:59

if sci would have defprotocol, but only supports extend via metadata, would this still be useful?

jeroenvandijk12:02:20

I havenโ€™t used the :extend-via-metadata yet, not sure

thumbnail19:02:29

at my work we use metadata based protocols (almost) everywhere

borkdude11:02:00

e.g.:

(defprotocol Component
  :extend-via-metadata true
  (start [component]))

(def component (with-meta {:name "db"} {`start (constantly "started")}))
(start component) ;; "started"