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
::schema-field2
::not-schema-field]))
(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}) => trueschemas are not exclusive
so yes
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
::schema-field2
::not-schema-field]))
and this:
(s/select [::schema-field1
::schema-field2
::not-schema-field]))
seem to express the samegen
docs
closed schema checking
I see, that makes sense, thanks
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 ๐
Isnโt s/form close to what you are looking for?
I'm interested in newline/comment preservation as well
Not for the faint of heart https://github.com/reducecombine/.lein/commit/ca5bccefd672191d5c703047d4e206304cac9453