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

Forward parser declaration gets unexpectedly "baked in" as unbound fn #19

Open
darwin opened this issue Mar 22, 2020 · 0 comments
Open

Comments

@darwin
Copy link

darwin commented Mar 22, 2020

I'm getting unexpected "Attempting to call unbound fn" when parsing recursive structure which relies on forward declaration. This is only problem with cold REPL. When I re-evaluate namespace in the REPL for third time it starts working.

I don't understand the underlying issue but it seems to me that my forward-declared var gets somehow baked into some parser(s) and when such parser gets later executed the var is not dynamically resolved but uses value from "compile-time".

Please see this minimal example [1]
run py-value does not work in cold REPL, see[2]
run py-value2 works, get-py-value2 wrapper is protecting py-value2 from being baked in.

[1]

(ns api-gen.impl.repro
  (:require [blancas.kern.core :refer :all]
            [blancas.kern.lexer.basic :refer :all]))

; broken case

(declare py-value)

(def py-set
  (bind [v (braces (comma-sep py-value))]
    (return (set v))))

(def py-value
  (<|> identifier
       py-set))


; working case

(declare py-value2)

(defn get-py-value2 [s]
  (py-value2 s))

(def py-set2
  (bind [v (braces (comma-sep get-py-value2))]
    (return (set v))))

(def py-value2
  (<|> identifier
       py-set2))

(comment

  (run py-value "{a, b, {aa}}")
  (run py-value2 "{a, b, {aa}}")

  )

[2]

Execution error (IllegalStateException) at blancas.kern.core/>>=$fn (core.clj:377).
Attempting to call unbound fn: #'api-gen.impl.repro/py-value
java.lang.IllegalStateException: Attempting to call unbound fn: #'api-gen.impl.repro/py-value
	at clojure.lang.Var$Unbound.throwArity(Var.java:45)
	at clojure.lang.AFn.invoke(AFn.java:32)
	at blancas.kern.core$_GT__GT__EQ_$fn__1668.invoke(core.clj:377)
	at blancas.kern.core$_GT__GT__EQ_$fn__1668.invoke(core.clj:377)
	at blancas.kern.core$_LT__BAR__GT_$fn__1665.invoke(core.clj:359)
	at blancas.kern.core$_GT__GT__EQ_$fn__1668.invoke(core.clj:377)
	at blancas.kern.core$_GT__GT__EQ_$fn__1668.invoke(core.clj:379)
	at blancas.kern.core$_GT__GT__EQ_$fn__1668.invoke(core.clj:377)
	at blancas.kern.core$_GT__GT__EQ_$fn__1668.invoke(core.clj:377)
	at blancas.kern.core$_LT__BAR__GT_$fn__1665.invoke(core.clj:361)
	at blancas.kern.core$parse.invokeStatic(core.clj:926)
	at blancas.kern.core$parse.invoke(core.clj:917)
	at blancas.kern.core$run.invokeStatic(core.clj:956)
	at blancas.kern.core$run.invoke(core.clj:949)
	at blancas.kern.core$run.invokeStatic(core.clj:953)
	at blancas.kern.core$run.invoke(core.clj:949)
	at api_gen.impl.repro$eval2217.invokeStatic(repro.clj:35)
	at api_gen.impl.repro$eval2217.invoke(repro.clj:35)
	at clojure.lang.Compiler.eval(Compiler.java:7177)
	at clojure.lang.Compiler.eval(Compiler.java:7132)
	at clojure.core$eval.invokeStatic(core.clj:3214)
	at clojure.core$eval.invoke(core.clj:3210)
	at clojure.main$repl$read_eval_print__9086$fn__9089.invoke(main.clj:437)
	at clojure.main$repl$read_eval_print__9086.invoke(main.clj:437)
	at clojure.main$repl$fn__9095.invoke(main.clj:458)
	at clojure.main$repl.invokeStatic(main.clj:458)
	at clojure.main$repl.doInvoke(main.clj:368)
	at clojure.lang.RestFn.invoke(RestFn.java:1523)
	at nrepl.middleware.interruptible_eval$evaluate.invokeStatic(interruptible_eval.clj:79)
	at nrepl.middleware.interruptible_eval$evaluate.invoke(interruptible_eval.clj:55)
	at nrepl.middleware.interruptible_eval$interruptible_eval$fn__940$fn__944.invoke(interruptible_eval.clj:142)
	at clojure.lang.AFn.run(AFn.java:22)
	at nrepl.middleware.session$session_exec$main_loop__1041$fn__1045.invoke(session.clj:171)
	at nrepl.middleware.session$session_exec$main_loop__1041.invoke(session.clj:170)
	at clojure.lang.AFn.run(AFn.java:22)
	at java.base/java.lang.Thread.run(Thread.java:830)
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