About recursive schemas. It seems that because of those, should to to add a (-children [this])
method into Schema
protocol. Why? Currently, there is generic children
function that returns the Schema AST for the children. The AST is unaware of any instance bindings such as local recursion targets. Given a Schema:
[:maybe {:id :cons}
[:tuple int? [:ref :cons]]]
, the generator for :tuple
just sees children of (int? [:ref :cons])
and doesn’t know what :cons
refers to and fails.We could hack around this by pulling out options that created :tuple
and using those to re-create the child schemas, providing all the needed local context. But, this is error-prone as one needs to wire-up all generators, visitors etc. using the original options from the father schema.
(currently passing the local context via options, which seems to be a good way to do it)
Anyway, this works now:
with recursion, one can set the recursion limit, just like with spec. One setting, but each :ref
is counted separatly, defaulting to 10.
wrote more to the recursion issue, comments welcome: https://github.com/metosin/malli/pull/117#issuecomment-647348039
I feel that having more than 1 way of defining recursive structures implies that users will have to choose which to use. Choice can sometimes be a problem more than a solution.