clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
Helins 2021-05-22T18:21:50.038500Z

Hey! I have been doing a lot of work involving generating recursive data. This is a space where actually, from what I see, neither Spec nor Malli have a working solution. Any trivial example is already too much and generation gets completely out of hand. However I haven't used Spec in a while so I might be mistaken. I'd appreciate your thoughts and comments, especially if you have encountered that kind of problems. Albeit extremely simple, with a pretty standard size of 30, generating a single instance of this example results commonly in 1000-3000 leaves (nested vectors containing that much booleans):

(s/def ::bool
  boolean?)

(s/def ::vec
  (s/coll-of ::data))

(s/def ::data
  (s/or :bool ::bool
        :vec ::vec))
There is an "exponential explosion" so that such definitions to not reflect the size linearly but rather exponentially. I tried explaining it thoroughly here and how test.check solves it with recursive-gen (the fact it is a Malli issue is irrelevant): https://github.com/metosin/malli/issues/452 So, surprisingly, it is somewhat impossible to generate truly random Clojure values where collection items can be collections as well. Unless I am of course missing something, so here I am :)