Fork me on GitHub
#clojure-spec
<
2020-08-13
>
ikitommi05:08:32

a common question for spec-tools has been how to create custom specs that coerce correctly and emit valid JSON Schema (for web-stuff). I though of pasting a sample here too for adding support for ZonedDataTime

ikitommi05:08:26

would be happy to throw away the custom wrappers for adding meta-data for specs in favour of core spec supporting that.

respatialized13:08:01

can I re-use a matched value within the body of spec/cat for further pattern matching later on by referring to its key? I'm trying something like:

(def lookup {:a 1 :b 2 :c 3})
(s/cat :key keyword?
       :contents (spec/* (spec/or :string string? :matched (get lookup :key))))
Is this possible?

Alex Miller (Clojure team)13:08:14

you can s/& at the top level and check constraints with any arbitrary predicate inside the container

respatialized13:08:26

ok, thanks! I think the space of possible keys in the lookup map I'd be relying on is small enough to fully enumerate using individual specs, so I think I'll just do that instead (probably what I should have been doing from the start, but I wanted to see if I could save myself some typing 😂)

johanatan17:08:22

is it possible to define a spec for a function in a namespace that one doesn't control?

johanatan17:08:51

so like

(s/fdef the-ns/the-func ...)  ?

johanatan17:08:08

ah cool. thx!

Alex Miller (Clojure team)17:08:25

fdef always takes fq symbols and those are just keys in the registry

apbleonard22:08:54

Anyone know whether spec2 is informed by SHACL? https://youtu.be/apG5K3zc4V0

👍 3
rickmoynihan08:08:49

FYI there is also a #rdf channel on here, it has infrequent but good discussions on it when they occur

apbleonard08:08:21

Thanks. Good to know :)

Alex Miller (Clojure team)22:08:35

while I find it's usually a bad bet to say that Rich is not aware of something, as far as I know he is not aware of that. certainly a lot of the design work precedes that talk

Alex Miller (Clojure team)22:08:22

from a quick skim of the video, both Rich and are I well-versed in RDF and OWL and that inspired many things in the design of both Clojure and Datomic (this is covered in some more detail in the History of Clojure paper https://clojure.org/about/history). I'm not sure that SHACL has anything particularly novel in it and it also makes a closed world assumption that's actually intentionally absent from spec to a large degree

Alex Miller (Clojure team)22:08:33

I actually started using Clojure at the semweb startup Revelytix about 10 years ago and wrote a commercial federated SPARQL engine there

Alex Miller (Clojure team)22:08:00

all in Clojure, sadly, no code survives from the company dying :(