Welcome! Please see the About page for a little more info on how this works.

+3 votes
in Spec by
edited by

I'm trying to implement traceability into my specs.
(With "specs" I specifically mean s/def and s/fdef blocks.)

Originally, I came up with the idea to use metadata for this. However, that's unfortunately not possible: the code below gives me a syntax error... (Metadata can only be applied to IMetas.)

(require
    '[clojure.spec.alpha :as s])
(s/def
      ^{:rule "205.3i"
        :version "2020.06.01"}
      ::basic-land-type #{::forest ::island ::mountain ::plains ::swamp})

The only other way I can think of is to somehow attach the metadata as a "guardian" element within the file (let's say, a def)

However, it seems quite ugly...

(def
  ^{:rule "205.3i"
    :version "2020.06.01"}
  tracing-info "(see metadata)")

Would anyone know some way I could use to achieve this?

2 Answers

+2 votes
by

There's not really a way to do this right now for all spec types, but it's basically the most frequent request w/ doc string support so we are going to look at it in spec 2.

The best workaround right now is probably to create your own secondary registry keyed by spec name and use that to hold metadata maps.

by
edited by
Thanks for the quick answer, @alexmiller!
Would you know about an illustrative example of this? _(Or to something similar to what you are describing.)_
Whereas I do understand the general idea, I have no clue about how to implement it...
by
Sorry, don't have anything handy. By a registry, I just mean an atom holding a map (which is exactly what the spec registry is), from spec name (keyword) to metadata.
by
Thanks anyways, @alexmiller. I think I now have a deeper understanding of your idea.
...