Fork me on GitHub
#clojure-spec
<
2016-07-05
>
wildermuthn01:07:31

Reading “Out of the Tarpit” (http://shaffner.us/cs/papers/tarpit.pdf), and maybe I’ve just got Spec on my mind, but this looks pretty familiar:

wildermuthn02:07:21

The article’s description of "Functional Relational Programming” includes a section on “Essential Logic” that seems to correspond very well with Spec!

Alex Miller (Clojure team)09:07:51

I think it's no accident that Clojure+Datomic overlap pretty well with Out of the Tarpit

Alex Miller (Clojure team)13:07:48

s/and flows conformed values through the predicates and the s/+ conforms to a vector

Alex Miller (Clojure team)13:07:36

Rich has mentioned a split into s/and and s/and-> to have both choices

vikeri14:07:28

@alexmiller: Thanks! Yes it could probably be useful sometimes to not have it flow through the predicates but evaluate them separately.

Alex Miller (Clojure team)15:07:20

separately, the need to validate this specific case of a regex and vector? is common and one I’ve run into many times in spec’ing macros and there might be some addition specifically for this

aengelberg20:07:26

Has there been any talk about allowing local registries to use with clojure spec functions rather than only using the global registry? Similar to (make-hierarchy) and derive.

Alex Miller (Clojure team)20:07:56

I haven't heard such talk :)

pdlug20:07:11

I’m trying to use multi-spec but it doesn’t seem to work with defmethod’s :default dispatch, is this a bug or intentional?

Paco20:07:33

I don’t think multi-spec behaves exactly like that. I believe there is no default to be had.

pdlug21:07:54

That’s unfortunate. Is there a better way to handle the validation where a field in the map determines the type and you want to explicitly constrain some types but provide a default base?

pdlug21:07:40

Ex: modeling analytics events, the :type provides the type of event, for :search events :terms are required, for :page-view events :url is required but for all other events there are no other constraints on the map

Paco21:07:39

It seems it only dispatches on key defined in s/multi-spec not on the this

Paco21:07:01

hmmm but I just tried (s/def :foo/bad-entity (s/multi-spec entity :does-not-exist)) (gen/sample (s/gen :foo/bad-entity) 1) and the program goes into an infinite loop

Paco21:07:32

wait! not infinite loop I just get ExceptionInfo Couldn't satisfy such-that predicate after 100 tries.

Paco21:07:45

makes sense it either matches a spec or it does not. I am back to my original argument 😛

pdlug21:07:36

I think it’s unexpected behavior if multi-spec works w/ multimethods but then doesn’t support the default behavior of them

Paco21:07:40

@pdlug: yah I had the same issue I want to dispatch on type but it has to be based on a key on your map 😞

pdlug21:07:57

I still don’t see anything else that supports my example use case

Paco21:07:49

yeah, my problem is that I want to dispatch on something else than a namespaced key on the map. I want to dispatch on meta from the map. Not always you want to expose the “type” on the actual entity

pdlug21:07:28

makes sense

Alex Miller (Clojure team)21:07:12

@pdlug you might also see if s/merge helps you in combining base+specific s/keys

Paco22:07:08

Yeah but you would be able to have a generic event spec for all the other types.