You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into a problem with recursive rules. I predeclared a var to get it to compile. However, at runtime, I get an unbound fn exception. Here's a simplified example. My work-around was to use a var in my recursive rule, rather than the normal function. Notice the xcon1 def. I couldn't find the problem in the squarepeg source. I hate to jump to any conclusions, but maybe it's a Clojure bug.
I ran into a problem with recursive rules. I predeclared a var to get it to compile. However, at runtime, I get an unbound fn exception. Here's a simplified example. My work-around was to use a var in my recursive rule, rather than the normal function. Notice the xcon1 def. I couldn't find the problem in the squarepeg source. I hate to jump to any conclusions, but maybe it's a Clojure bug.
(ns miner.herbert.recursive
(:require [squarepeg.core :as sp]))
(declare mcon)
(def mint (sp/mkpr integer?))
(def mvec (sp/mksub (sp/mk1om mcon)))
(def mcon (sp/mkalt mint mvec))
_ (mcon '(42) {} {} {})
;=> {:i (), :b {}, :r 42, :s [42], :m {}}
_ (mcon '([42]) {} {} {})
; IllegalStateException Attempting to call unbound fn: #'miner.herbert.recursive/mcon
; clojure.lang.Var$Unbound.throwArity (Var.java:43)
;; Same thing with a slight variation of use the xcon1 var for the recursive rule.
(declare xcon)
;; work-around by using var
(def xcon1 #'xcon)
(def xint (sp/mkpr integer?))
(def xvec (sp/mksub (sp/mk1om xcon1)))
(def xcon (sp/mkalt xint xvec))
_ (xcon '(42) {} {} {})
;=> {:i (), :b {}, :r 42, :s [42], :m {}}
_ (xcon '([42]) {} {} {})
;=> {:i (), :b {}, :r [42], :s [42], :m {}}
The text was updated successfully, but these errors were encountered: