clojure-spec

borkdude 2021-12-08T16:53:30.231600Z

I'm working on better clojure.spec support for babashka. I'm testing expound with instrumentation. How do people generally get to see expound's output when running with instrumented functions? What do you have to configure, besides the explain printer? It seems you have to catch the ExceptionInfo and push the ex-data through s/explain-out yourself?

borkdude 2021-12-08T16:54:21.232200Z

Besides that question: what are some libraries that leverage clojure.spec that I should test.

vemv 2021-12-12T22:58:14.245Z

https://github.com/nedap/speced.def perhaps, we've wanted to use it for bb scripting sometimes (@jeroen.dejong)

➕ 1
Kirill Chernyshov 2021-12-08T17:11:06.232300Z

reitit with spec based coercions

borkdude 2021-12-08T17:12:08.232500Z

reitit doesn't work because it isn't pure Clojure, it has custom Java classes

lucian303 2021-12-22T21:53:18.278400Z

spec tools: https://cljdoc.org/d/metosin/spec-tools/0.10.5/doc/readme

abrooks 2021-12-08T23:03:53.237400Z

We have a library that provides and conforms against specs for incoming complex values. Within the values can be maps and s/keys will, as the doc string says: > In addition, the values of all namespace-qualified keys will be validated (and possibly destructured) by any registered specs. If the caller puts their own namespaced keys in the map (which is fine) and they have defined specs for these, those specs will be validated (and conformed) when we validate or conform the larger structure. This creates problems in providing good error messages since, when we conform, we don't know if the caller has violated our spec or their own spec. There's no way to conform only our parts of the spec first to validate the shape of their input without also conforming and failing on their values. This leads to a very confusing error message that we can't help to resolve.

abrooks 2021-12-08T23:04:43.238300Z

Is there a sane work around for this? I'd really like an s/keys option or similar that doesn't validate keys beyond those expressed.

Alex Miller (Clojure team) 2021-12-08T23:26:30.239400Z

a) you could narrow the data before conforming b) hopefully you can differentiate by key namespace either for narrowing or for error gen?

👍 1
abrooks 2021-12-17T14:30:03.270700Z

(a) doesn't work since we actually want the data preserved in the conformed result. I'll look at (b) but would love to mention that having local specs (similar to local Clojure hierarchies) is really what I think I want as a user. You can have the global spec (just like global-hierarchy) but also provide a local subset or curated spec for a particular context.

Alex Miller (Clojure team) 2021-12-17T14:35:11.270900Z

yeah, that's not in line with the spec rationale https://clojure.org/about/spec#_global_namespaced_names_are_more_important

abrooks 2021-12-17T18:38:13.271100Z

Oh, I love namespaced names and the general global usage is fine but, as Stu and Rich have noted, a la carte features are valuable for application domain use cases not just programming domain use cases. I'd love to have spec for application domain use cases which is exactly what hierarchies allows for. Global for programming domain, a la carte for application domain. Often the specs overlap so you want to be able to re-use them between the two.

abrooks 2021-12-17T18:38:53.271300Z

metosin/malli supports this, FWIW.

Drew Verlee 2021-12-08T00:50:22.226900Z

> For this we have exercise, which returns pairs of generated and conformed values for a spec What if we just want the generated values?

Drew Verlee 2021-12-08T00:51:24.227800Z

i can fish them out, but i'm guessing there is a convention rather then threading with calls to first.

Alex Miller (Clojure team) 2021-12-08T02:00:23.228300Z

you can call gen/sample if you just want generated values https://clojure.github.io/spec.alpha/clojure.spec.gen.alpha-api.html#clojure.spec.gen.alpha/sample

👍 1
Alex Miller (Clojure team) 2021-12-08T02:01:24.228700Z

sorry, https://clojure.github.io/test.check/clojure.test.check.generators.html#var-sample is the docstring for that

Drew Verlee 2021-12-08T03:49:19.229Z

thanks alex. ill read that shortly!

Drew Verlee 2021-12-08T04:38:46.229700Z

that likely does what i need. it would be nice if i had away to easily jump from one doc to another. that fns args are are just & args and the doc string is that its a lazy version of another fn. not much to go off! i guess i should just jump to the code?

Drew Verlee 2021-12-08T04:41:16.230Z

well, im guessing that would be very educational

(lazy-combinators hash-map list map not-empty set vector vector-distinct fmap elements
  bind choose one-of such-that tuple sample return
  large-integer* double* frequency shuffle)

Drew Verlee 2021-12-08T04:41:27.230200Z

but not very direct 🙂