Clojure

Can't make a dispatch map containing forward-declared fns

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Declined
  • Affects Version/s: Release 1.6
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

If from (ns tst2) you try to call tst1/c, which calls tst1/f via dispatch map which was defined when tst1/f was forward declared, you get an "unbound fn" error. E.g.

user=> (dorun (map eval 
                   '[(ns tst1) 
                     (declare f) 
                     (def d {:k f}) 
                     (defn c [] ((d :k)))
                     (defn f [] :success)
                     (ns tst2 (:require [tst1]))
                     (tst1/c)]))

IllegalStateException Attempting to call unbound fn: #'tst1/f  clojure.lang.Var$Unbound.throwArity (Var.java:43)
tst2=> (clojure.repl/pst *e)
IllegalStateException Attempting to call unbound fn: #'tst1/f
	clojure.lang.Var$Unbound.throwArity (Var.java:43)
	tst1/c (NO_SOURCE_FILE:5)
	tst2/eval25 (NO_SOURCE_FILE:8)
	clojure.lang.Compiler.eval (Compiler.java:6642)
	clojure.lang.Compiler.eval (Compiler.java:6605)
	clojure.core/eval (core.clj:2883)
	clojure.core/map/fn--4222 (core.clj:2513)
	clojure.lang.LazySeq.sval (LazySeq.java:40)
	clojure.lang.LazySeq.seq (LazySeq.java:49)
	clojure.lang.RT.seq (RT.java:484)
	clojure.core/seq (core.clj:133)
	clojure.core/dorun (core.clj:2811)

Activity

Alex Coventry made changes -
Field Original Value New Value
Attachment unbound-eg.tgz [ 12308 ]
Alex Miller made changes -
Description If from (ns tst2) you try to call tst1/c, which calls tst1/f via dispatch map which was defined when tst1/f was forward declared, you get an "unbound fn" error. E.g.

lap% lein repl
nREPL server started on port 45848 on host 127.0.0.1
REPL-y 0.2.1
Clojure 1.5.1
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)

user=> (dorun (map eval '[(ns tst1) (declare f) (def d {:k f}) (defn c [] ((d :k))) (defn f [] :success) (ns tst2 (:require [tst1])) (tst1/c)]))
(dorun (map eval '[(ns tst1) (declare f) (def d {:k f}) (defn c [] ((d :k))) (defn f [] :success) (ns tst2 (:require [tst1])) (tst1/c)]))

user=> IllegalStateException Attempting to call unbound fn: #'tst1/f clojure.lang.Var$Unbound.throwArity (Var.java:43)
If from (ns tst2) you try to call tst1/c, which calls tst1/f via dispatch map which was defined when tst1/f was forward declared, you get an "unbound fn" error. E.g.

{code}
user=> (dorun (map eval
                   '[(ns tst1)
                     (declare f)
                     (def d {:k f})
                     (defn c [] ((d :k)))
                     (defn f [] :success)
                     (ns tst2 (:require [tst1]))
                     (tst1/c)]))

IllegalStateException Attempting to call unbound fn: #'tst1/f clojure.lang.Var$Unbound.throwArity (Var.java:43)
tst2=> (clojure.repl/pst *e)
IllegalStateException Attempting to call unbound fn: #'tst1/f
clojure.lang.Var$Unbound.throwArity (Var.java:43)
tst1/c (NO_SOURCE_FILE:5)
tst2/eval25 (NO_SOURCE_FILE:8)
clojure.lang.Compiler.eval (Compiler.java:6642)
clojure.lang.Compiler.eval (Compiler.java:6605)
clojure.core/eval (core.clj:2883)
clojure.core/map/fn--4222 (core.clj:2513)
clojure.lang.LazySeq.sval (LazySeq.java:40)
clojure.lang.LazySeq.seq (LazySeq.java:49)
clojure.lang.RT.seq (RT.java:484)
clojure.core/seq (core.clj:133)
clojure.core/dorun (core.clj:2811)
{code}
Alex Miller made changes -
Resolution Declined [ 2 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: