Fork me on GitHub

Given an fdef , can I get its source code back? Like clojure.repl/source does with vanilla defs (my guess is that nope, but maybe someone wrote a thing?)


Maybe create a macro that uses a central registry to keep track of the source of each fdef, as per its fully evaluated name.


Not cool enough with macros to write the example, but it’d be something like, swap!ing into your central atom, where you keep a map of fdef-symbol -> unevaluated source, and then of course evaluating your fdef normally afterwards.


This is just an off-hand idea, hope it makes sense


I think a minimalistic macro is a step in the right direction, thanks! Hadn't thought of that much In that case I wouldn't need an extra atom - I could simply let clojure.repl/source do its work e.g. (defmacro def-fdef ..) + (def-fdef the-defn the-spec) The macro would create a predictable symbol, like the-defn-fdef-source . Then I (source the-defn-fdef-source)


hm, yeah, I guess 🙂


Looking forward to see how you fare 🙂

🙂 2
Lennart Buit11:08:11

Isn’t s/form close to what you are looking for?

👍 2

I'm interested in newline/comment preservation as well


Currently, on spec alpha 2, you can select things that are not in the schema passed. Is this expected behaviour?

(ns user
  (:require [clojure.alpha.spec :as s]))

(s/def ::schema-field1 int?)
(s/def ::schema-field2 int?)
(s/def ::not-schema-field int?)

(s/def ::schema (s/schema [::field1 ::field2]))
(s/def ::selected (s/select ::schema [::schema-field1

(s/valid? ::selected {::schema-field1 1
                      ::schema-field2 2
                      ::not-schema-field true}) => false

(s/valid? ::selected {::schema-field1 1
                      ::schema-field2 2
                      ::not-schema-field 3}) => true

Alex Miller (Clojure team)18:08:58

schemas are not exclusive


Great, thank you! I think it’s great to contextually ‘extend’ schema selections to keywords not originally on the schema


Is there any reason to have a schema in select at all? This:

(s/select ::schema [::schema-field1
and this:
(s/select [::schema-field1
seem to express the same


I see, that makes sense, thanks