Fork me on GitHub
#malli
<
2020-06-22
>
ikitommi07:06:39

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.

ikitommi07:06:27

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.

ikitommi07:06:58

(currently passing the local context via options, which seems to be a good way to do it)

ikitommi07:06:14

Anyway, this works now:

ikitommi07:06:59

with recursion, one can set the recursion limit, just like with spec. One setting, but each :ref is counted separatly, defaulting to 10.

Vincent Cantin14:06:47

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.

👀 3