Skip to content
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

recursive rules with declare causes unbound fn exception #7

Open
miner opened this issue Jun 10, 2013 · 0 comments
Open

recursive rules with declare causes unbound fn exception #7

miner opened this issue Jun 10, 2013 · 0 comments

Comments

@miner
Copy link
Collaborator

miner commented Jun 10, 2013

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 {}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant