Fork me on GitHub
#lambdaisland
<
2020-02-12
>
plexus09:02:23

The above issue should be fixed now, thanks @borkdude. Not sure about the data reader but I might add a macro version.

borkdude09:02:29

Hey cool. What about removing test.check from the main dependencies? I would suggest letting users bring in test.check themselves (like for clojure.spec, etc)

plexus09:02:30

yes, that seems like a good idea. I'll do the same with spec / spec-alpha2 / malli in the future, as the idea is to provide integrations with those.

borkdude10:02:42

the way CLJS solves this is to let users require test.check explicitly themselves and then check in the namespaces that use it if it's already required, if not, emit a warning. I like that solution better than the dynaload thing that JVM Clojure does which seems more complex.

borkdude10:02:50

Note that usage as data reader already works:

$ clj -Sdeps '{:deps {regal {:git/url "" :sha "468195aa81fcbd73c2c8e566c57411f359950a23"}}}'
Clojure 1.10.1
user=> (require '[lambdaisland.regal :as re] '[clojure.edn :as edn])
nil
user=> (edn/read-string {:readers {'regal/regex re/regex}} "#regal/regex [:range \\A \\Z]")
#"[A-Z]"
Maybe nice to add to the docs.

plexus11:02:35

I would rather not encourage using a data reader for this. I'm becoming wary of data reader overuse. A regal expression is already plain data and so can go into EDN fine. If you want to precompile you can use a macro or cache the result. The presence of a data reader implies the presence of a printer, which there isn't.

borkdude11:02:51

ok. about the other issue you just closed: I don't think that's fixed at all test.check is still brought in as a dependency https://github.com/lambdaisland/regal/blob/468195aa81fcbd73c2c8e566c57411f359950a23/deps.edn#L3 and lambdaisland.regex still requires the generators namespace, so it's not optional at all

borkdude11:02:35

aaaanyway...

plexus11:02:44

right the top level namespace does provide a shorthand for generators/gen and generators/sample... you're right this needs a little more smarts

plexus11:02:18

and I should remember to git push...

borkdude11:02:46

I'd say just take a look at how malli does it, it's the same as my suggestion

plexus11:02:01

So taking out the top level require

borkdude11:02:10

i.e. the generators namespace should probably not be loaded by the "core" namespace

plexus11:02:18

Yeah... definitely the easiest approach

borkdude11:02:59

small price to pay I'd say for users who do want to use the generators: they are going to require the test.check + lambdaisland.regal/generators namespace

plexus11:02:18

then I might as well get rid of the top level, it'll just be a

(defn regex [r]
  (pattern/regex r))

borkdude11:02:48

I used that in speculative to test specs for re-find, etc.

plexus11:02:09

I was not, thanks for the pointer!

plexus11:02:35

might look at how they do the regex parsing, as it would be great to be able to go regex -> regal in the future

borkdude11:02:02

might be nice to link to prior / alternative work in this area (there are some others which I can't think of of the top of my head right now)

plexus11:02:33

I was pointed at the Common Lisp equivalent, which would be interesting to study

plexus15:02:16

The top level no longer depends on generators, instead l.r.pattern has been promoted/renamed to the top level lambdaisland.regal