Help needed with schema for a recursive data structure

60 views
Skip to first unread message

Dmitriy Morozov

unread,
May 31, 2018, 10:53:32 AM5/31/18
to Plumbing and Graph: the Clojure utility belt
Hi everyone! I'm trying to define a Schema for a recursive data structure but can't figure it out.
I tried using functions from the 'schema.recursive' with no luck. Following solution produces StackOverflow.

https://gist.github.com/erasmas/02cb93ca6f7d7c7a2b8b29927ffe11d6

I would appreciate if somebody could guide me in the right direction with this schema.

Thanks!

Jason Wolfe

unread,
May 31, 2018, 12:04:49 PM5/31/18
to Plumbing and Graph: the Clojure utility belt
Hi! 

"either" is deprecated and does not work with recursive schemas (see e.g. https://github.com/plumatic/schema/issues/359#issuecomment-219013302). 
You need to use something like "cond-pre" or "conditional" instead.  This will also make your error messages much better, etc.

In your case, you can't use "cond-pre" since your things all look the same.  But you should be able to do something like: `(defschema Val (s/conditional #(= (% 1) 'Int) IntVal ...))`.

LMK if you have questions or that doesn't work for you.

Best, Jason

Dmitriy Morozov

unread,
Jun 1, 2018, 3:12:38 AM6/1/18
to Plumbing and Graph: the Clojure utility belt
Thanks for the prompt response, Jason! I followed your advice and rewrote my schema using s/conditional.

https://gist.github.com/erasmas/02cb93ca6f7d7c7a2b8b29927ffe11d6

Thanks a lot!

четвер, 31 травня 2018 р. 19:04:49 UTC+3 користувач Jason Wolfe написав:
Reply all
Reply to author
Forward
0 new messages