Skip to content

recursive rules with declare causes unbound fn exception #7

Description

@miner

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions