metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.48k stars 210 forks source link

Error when using recursive schema in seq: potentially-recursive-seqex #914

Closed misterzirillo closed 1 year ago

misterzirillo commented 1 year ago

I am trying to create a schema to express a few clojure functions like so

(def ExpressionNumericFunction
 [:and
  list?
  [:cat
   [:enum '+ '- '* '/ 'max 'min 'avg]
   [:+ [:ref ::numeric]]]])

(def ExpressionNumeric
 [:schema {:registry {::numeric
                      [:or
                       number?
                       ExpressionNumericFunction
                       ]}}
  [:ref ::numeric]])

However, I get the error :malli.core/potentially-recursive-seqex when trying to reify the schema. Indeed this is a recursive definition inside a sequence. I get the feeling this may not be supported?

camsaul commented 1 year ago

Try [:schema [:ref ...]]. Sometimes that solves it

misterzirillo commented 1 year ago

@camsaul I used [:schema [:ref ...]] in my example. Not sure what else there is to try.

camsaul commented 1 year ago

You need to use :schema in the seqex, e.g. [:+ [:schema [:ref :numeric]]]

ikitommi commented 1 year ago

Yes, Malli doesn't support recursive schemas as part of a sequence schema itself, but you can wrap the schema into :schema to allow recursive schemas as individual childs. Here's a definition for hiccup in malli.io.