Schema-checking the constructor functions

21 views
Skip to first unread message

Maarten Truyens

unread,
Mar 11, 2016, 12:50:47 AM3/11/16
to Plumbing and Graph: the Clojure utility belt
Hi,

It seems that, even when set-fn-validation! is set to true, the constructor functions map->X and ->X do not schema-check their arguments.

Is this a deliberate decision? It seems to me that it would be very useful to schema-check data "at the entrance gates"...

Regards,

Maarten

Jason Wolfe

unread,
Mar 11, 2016, 12:56:40 AM3/11/16
to Maarten Truyens, Plumbing and Graph: the Clojure utility belt
I think in the past there were two potential reasons why this wasn't done:
- The order things are defined (s/defrecord before s/fn) made it challenging
- If you need the fastest possible performance, it might be
considered bad form to add (even a tiny) overhead to the built-in
constructor functions.

I think the first is no longer a problem, and the second is probably
moot (the overhead is very low, and you can always use the Java
constructor if you need every last inch of performance). We'd happily
take a PR (especially if it came with benchmarks about ->X
performance, just to double-check). Or in any case, please feel free
to open an issue.

Thanks!
Jason
> --
> You received this message because you are subscribed to the Google Groups
> "Plumbing and Graph: the Clojure utility belt" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to prismatic-plumb...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Maarten Truyens

unread,
Mar 14, 2016, 1:26:01 PM3/14/16
to Plumbing and Graph: the Clojure utility belt, maa...@siteffects.be
Thanks, I'll give it a try (but this code base is not the very easiest to start with :-)) 

Jason Wolfe

unread,
Mar 15, 2016, 2:35:13 AM3/15/16
to Maarten Truyens, Plumbing and Graph: the Clojure utility belt
Thanks! :) I think it should just be a matter of changing the `defn`s
here to `schema.core/defn` and adding return schemas, and then adding
some tests.

https://github.com/plumatic/schema/blob/master/src/clj/schema/macros.clj#L318
Reply all
Reply to author
Forward
0 new messages