This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-26
Channels
- # asami (5)
- # babashka (9)
- # beginners (19)
- # calva (14)
- # cider (13)
- # clj-kondo (9)
- # cljfx (2)
- # clojure (51)
- # clojure-bay-area (1)
- # clojure-europe (26)
- # clojurescript (23)
- # code-reviews (7)
- # core-async (1)
- # datahike (4)
- # datalevin (3)
- # emacs (2)
- # kaocha (2)
- # malli (6)
- # nrepl (3)
- # polylith (3)
- # re-frame (15)
- # reveal (1)
- # shadow-cljs (13)
- # tools-deps (6)
in addition to the above good advice, I would bind the regexes to meaningful names in a let block or def. I would have suggested some names to bind but it's too hard figuring out what each step is meant to do.
also #()
instead of named functions here is actively hostile to readers
since #
and %
so readily blend in with the regex syntax when skimming
java regexes (which is what #"" becomes) support in-line comments via a syntax switch, it's a judgment call whether using a feature most people don't know is worth it for the readability on the regex https://www.regular-expressions.info/ https://www.regular-expressions.info/java.html
Clojure 1.10.1
(cmd)user=> (def x-y-split
#"(?x) x # pattern must start with x
(.) # capture the item in the middle
y # pattern must end with y")
#'user/x-y-split
(cmd)user=> (re-seq x-y-split "xayxby")
(["xay" "a"] ["xby" "b"])
personally I would argue that using regular expression already means you expect users to deal with features that are obscure and I find this style of re much easier to readto elaborate a bit more (?x)
is a syntax switch, and it turns on two features that I care about here: ignoring whitespace and allowing #
comments until end of line
finally - I should have linked this - the docs for "free spacing mode" which is what the syntax ?x
enables is called https://www.regular-expressions.info/freespacing.html
Thank you, that does help with the crazy regexes!