Clojure Best Practice: When to use Metadata? -
i don't mean subjective question -- trying understand why with-meta in language. realize can used many purposes (so can eval, use outside specific circumstances sign of bad design). design perspective, unique purpose clojure's metadata structure serve? documentation? sugar?
what strong applications with-meta/meta? in cases bad idea? can give example of use of metadata impossible/difficult/tedious without it?
several of core features of language depend on metadata:
macros 1 feature depends on metadata. macro function bit of metadata causes function run @ compiletime.
user> (meta #'when) {:macro true, :ns #<namespace clojure.core>, :name when, :arglists ([test & body]), :column 1, :added "1.0", :doc "evaluates test. if logical true, evaluates body in implicit do.", :line 471, :file "clojure/core.clj"}types feature of language depends on metadata. type of expressed metadata on object.
tests use metadata. when (or lein) call
run-testslooks @ metadata on functions in each namespace find ones tests.
there many more cases ranging core of language types peripheral things n-repl/cider displaying function arguments @ bottom of screen while work use metadata. not design smell use metadata provided not using ugly things of course ;)
Comments
Post a Comment