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

0 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.)

    '[clojure.spec.alpha :as s])
      ^{: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...

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

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

1 Answer

+2 votes

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.

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...
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.
Thanks anyways, @alexmiller. I think I now have a deeper understanding of your idea.