Fork me on GitHub
#clojure-spec
<
2016-08-06
>
lvh00:08:20

Has anyone worked on a datalog spec?

eggsyntax00:08:48

@lvh: I’ve been doing a spec for our datomic data, but I’m generating specs from our (somewhat customized) schema definition vectors, not from the datalog itself. In retrospect I might have derived them from the datalog in the interest of greater generality.

eggsyntax00:08:23

We have some custom code that takes things like:

[[:ti/install-type :ti/Location []
  "A location in the real world that can be the source or destination of a shipment"
  {:id [:uuid :identity "Unique ID for the location"]
   :name [:string :fulltext "The name of the loaction"] ...]]
and turns them into vanilla datomic schema defs.

lvh01:08:22

Yep, makes sense :)

levitanong06:08:21

Hi all, is there a way to use multi-spec with a multimethod that takes two arguments instead of one? I’d like to be able to dispatch on a key/value outside of the map being mult-spec’d. Another way of describing the problem is: I have some map of the shape:

{:message/uuid uuid
 :message/action :some-action
 :message/payload {}}
:message/payload changes its shape based on :message/action.

levitanong06:08:43

As far as I can tell, multi-specs only allow you to dispatch on a key/value inside of the data structure. i.e. it would only be able to do the following:

{:message/uuid uuid
 :message/payload
   {:payload/action :some-action
   ;; other data here
}}
This is what I’m currently using, but I think it is more appropriate to place the :action as part of the message, and not the payload.

seancorfield20:08:18

@levitanong: consider the message as a whole -- although it has the same three keys in every case, the spec for :message/payload would be different in each arm of the multi spec.

atroche23:08:31

I started on a custom formatter for :cljs.spec/problems in cljs-devtools if anyone wants to carry on the work: https://github.com/gfredericks/schpec/issues/2#issuecomment-238005568

atroche23:08:20

i’ve done the small amount of plumbing required, and what’s left is to experiment with making it look nice