clojure-spec

bortexz 2021-08-23T18:10:26.067500Z

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}) => true

Alex Miller (Clojure team) 2021-08-23T18:18:58.067700Z

schemas are not exclusive

Alex Miller (Clojure team) 2021-08-23T18:19:15.067900Z

so yes

bortexz 2021-08-23T18:24:20.070800Z

Great, thank you! I think itโ€™s great to contextually โ€˜extendโ€™ schema selections to keywords not originally on the schema

bortexz 2021-08-23T18:27:46.072700Z

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 same

Alex Miller (Clojure team) 2021-08-23T18:30:44.072900Z

gen

Alex Miller (Clojure team) 2021-08-23T18:30:52.073100Z

docs

Alex Miller (Clojure team) 2021-08-23T18:31:01.073300Z

closed schema checking

bortexz 2021-08-23T18:32:02.073600Z

I see, that makes sense, thanks

vemv 2021-08-23T04:15:12.063900Z

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?)

reefersleep 2021-08-23T10:19:30.064300Z

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

reefersleep 2021-08-23T10:19:59.064500Z

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.

reefersleep 2021-08-23T10:22:52.065Z

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

vemv 2021-08-23T10:31:09.065200Z

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)

reefersleep 2021-08-23T10:33:10.065400Z

hm, yeah, I guess ๐Ÿ™‚

reefersleep 2021-08-23T10:34:05.065600Z

Looking forward to see how you fare ๐Ÿ™‚

๐Ÿ™‚ 1
2021-08-23T11:17:11.065900Z

Isnโ€™t s/form close to what you are looking for?

๐Ÿ‘ 1
vemv 2021-08-23T11:27:44.066100Z

I'm interested in newline/comment preservation as well

vemv 2021-08-23T19:05:30.073700Z

Not for the faint of heart https://github.com/reducecombine/.lein/commit/ca5bccefd672191d5c703047d4e206304cac9453

๐Ÿ‘€ 1