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
vlaaad 2021-02-13T13:08:09.032700Z

I was playing with built-in specs and discovered there are A LOT of places to embed var metadata in defn:

(defn ^{:b 1} foo
  {:c 1}
  ([])
  {:a 1})
:a , :b and :c all end up in var meta!

vlaaad 2021-02-13T13:09:30.033400Z

I wonder how's that, and why :arity-n defn variation allows attr map at the end...

vemv 2021-02-13T15:53:58.033500Z

> I wonder how's that I guess it's because if there was just one place, people could accidentally place it elsewhere and get no metadata attached

alexmiller 2021-02-13T16:52:22.036900Z

I found that when I spec’ed it and asked Rich about it. The thought at the time was that metadata might get big (this predated some of the ^ syntax) and it would obscure the main part of the function so you could put it at the end

alexmiller 2021-02-13T16:52:54.037800Z

It’s rarely used but I did find some places using when testing a spec without it

vlaaad 2021-02-13T19:01:13.037900Z

Very interesting, thanks for this explanation!