-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infinite loop on recursive specs/schemas #36
Comments
Unfortunately, I'm not sure I have a good solution to recursive definitions. Its something I thought a lot about when initially building Norm. I've thought of 2 ways to make it work but both have issues. Use macros for everythingCurrently Support symbolic calls or spec namesRight now there's no way to "export" or reference a spec. So we have to use functions. But since functions calls are eager we end up infinitely recursing. I've considered supporting something like this: defspec :tree_spec, do: one_of([{:terminal, spec(is_binary())}, {:node, :tree_spec}]) In this case These are the best ways I've come up with to solve this problem holistically. At the moment I'm leaning towards symbolic calls and |
I started playing around with the |
Another option I just thought about (but haven't fully considered yet) is the idea of supporting |
I am running into this right now. I'm not sure if this is a good idea but I'm processing a swagger file and turning it into Norm specs. The swagger spec includes some recursive definitions. It's impossible to define a recursive schema in norm, but it is possible to call I wonder if it might be possible to accept not only boolean output from predicates, but also allow them to call I might experiment a little with this to see if it's something that could be done without too much difficulty. |
I'm using the Floki web parsing library and have defined the following specs for use in my own code:
Note that
floki_html_children_nodes()
makes a recursive reference to thefloki_html_tag()
spec. I don't get an error, but my code enters an infinite loop while my laptop gets very loud and very hot. (To be clear, the data structure is a tree, but its definition is a cyclical graph, which is presumably what's "trapping" the Norm parsing code.)My workaround is to "dumb down" the definition of
floki_html_children_nodes()
, which makes my code run but isn't giving me the code safety that I want:Then again, one is mostly dealing with small fragments of html, having targeted the specific fragments while parsing, and one mostly only cares about the top level or two of any particular html sub-tree. There may also be a trade off to make between speed and granular accuracy.
On a related note, and perhaps worthy of another issue, is how to deal with third-party libraries. I don't necessarily want to go down Typescript's
index.d.ts
rabbit-hole. And perhaps it's easy enough to define one's own specs (at the granularity one requires for one's use of them).The text was updated successfully, but these errors were encountered: