Macros and macro helpers used in schema.core.
Replicate pre/postcondition logic from clojure.core/fn.
(assert! form & format-args)
Like assert, but throws a RuntimeException (in Clojure) and takes args to format.
Take the &env from a macro, and tell whether we are expanding into cljs.
(compile-fn-validation? env fn-name)
Returns true if validation should be included at compile time, otherwise false.
Validation is elided for any of the following cases:
* function has :never-validate metadata
* *compile-fn-validation* is false
* *assert* is false AND function is not :always-validate
(emit-defrecord defrecord-constructor-sym env name field-schema & more-args)
(error! s m)
Generate a cross-platform exception appropriate to the macroexpansion context
(if-cljs then else)
(input-schema-form regular-args rest-arg)
(maybe-split-first pred s)
(normalized-defn-args env macro-args)
Helper for defining defn-like macros with schemas. Env is &env
from the macro body. Reads optional docstring, return type and
attribute-map and normalizes them into the metadata of the name,
returning the normalized arglist. Based on
Helper for schema.core/=>*.
(process-arrow-schematized-args env args)
Take an arg vector, in which each argument is followed by an optional :- schema,
and transform into an ordinary arg vector where the schemas are metadata on the args.
(process-fn- env name fn-body)
Process the fn args into a final tag proposal, schema form, schema bindings, and fn form
(process-fn-arity env fn-name output-schema-sym bind-meta [bind & body])
Process a single (bind & body) form, producing an output tag, schema-form,
and arity-form which has asserts for validation purposes added that are
executed when turned on, and have very low overhead otherwise.
tag? is a prospective tag for the fn symbol based on the output schema.
schema-bindings are bindings to lift eval outwards, so we don't build the schema
every time we do the validation.
(safe-get m k)
Like get but throw an exception if not found. A macro just to work around cljx function
Globally turn on or off function validation from being compiled into s/fn and s/defn.
Enabled by default.
See (doc compile-fn-validation?) for all conditions which control fn validation compilation
(simple-arglist-schema-form rest? regular-args)
(single-arg-schema-form rest? [index arg])
(split-rest-arg env bind)
(try-catchall & body)
A cross-platform variant of try-catch that catches all exceptions.
Does not (yet) support finally, and does not need or want an exception class.
(valid-tag? env tag)
(validation-error schema value expectation & [fail-explanation])