clojure-spec

peterdee 2021-10-28T22:19:33.013900Z

Hi! At one time there was a function spec* in spec-alpha2 that allowed programmatic definition of specs. I don’t see that in the current SHA version. Is it still possible to define specs programmatically?

seancorfield 2021-10-28T22:22:30.014200Z

Are you looking for register @peterd? https://github.com/clojure/spec-alpha2/blob/master/src/main/clojure/clojure/alpha/spec.clj#L429

peterdee 2021-10-28T22:36:35.020400Z

I am looking at some code I wrote about two years ago. (Wish I could recall!) I was using both s/spec* and s/register. I was using backquoted forms or variable values with spec*. Hmmm… It looks like the spec* calls are typically wrapped in a s/register, but s/register takes a spec, not a body (form) so my guess is that register isn’t going to allow programmatic operation???

Alex Miller (Clojure team) 2021-10-28T22:40:23.021500Z

You probably want resolve-spec or maybe create-spec depending on what you're doing

Alex Miller (Clojure team) 2021-10-28T22:41:32.022300Z

resolve-spec takes a form and returns a spec object

peterdee 2021-10-28T22:42:54.023Z

Ugh! How did I miss that? Yes, I think resolve-spec.

peterdee 2021-10-28T22:42:59.023200Z

Thanks!

peterdee 2021-10-28T22:50:38.024300Z

Thanks. My program is happy again.

peterdee 2021-10-28T22:52:06.024700Z

Guess I should have looked at the commit log!

Alex Miller (Clojure team) 2021-10-28T23:06:22.025400Z

I think https://clojure.github.io/spec-alpha2/ is relatively synced to the code too

peterdee 2021-10-28T23:10:56.027800Z

Simple programmatic access is a nice feature. I’m wrote a parser for MiniZinc, a popular open-source combinatorial solver language; it has its own language for defining data. (Will open source my parser soon). The specs allow you to catch users errors that the parser misses.