clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
ikitommi 2020-08-13T05:16:32.106400Z

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

ikitommi 2020-08-13T05:17:08.106500Z

ikitommi 2020-08-13T05:23:26.110Z

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

respatialized 2020-08-13T13:12:01.114700Z

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?

alexmiller 2020-08-13T13:13:52.114900Z

no

alexmiller 2020-08-13T13:14:14.115400Z

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

respatialized 2020-08-13T13:18:26.117Z

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 😂)

johanatan 2020-08-13T17:35:22.117300Z

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

alexmiller 2020-08-13T17:35:53.117900Z

yes

johanatan 2020-08-13T17:36:17.118300Z

how?

alexmiller 2020-08-13T17:36:27.118500Z

the same way?

johanatan 2020-08-13T17:36:51.118900Z

so like

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

alexmiller 2020-08-13T17:36:58.119100Z

yep

johanatan 2020-08-13T17:37:08.119400Z

ah cool. thx!

alexmiller 2020-08-13T17:37:25.119700Z

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

johanatan 2020-08-13T18:15:13.119900Z

👍

apbleonard 2020-08-13T22:19:54.121500Z

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

👍 1
2020-08-19T08:08:49.165300Z

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

apbleonard 2020-08-19T08:11:21.165500Z

Thanks. Good to know :)

alexmiller 2020-08-13T22:30:35.122600Z

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

alexmiller 2020-08-13T22:38:22.124400Z

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

alexmiller 2020-08-13T22:39:33.125300Z

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

alexmiller 2020-08-13T22:40:00.125900Z

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