Using defining macros as non top-level forms may not be forbidden by the 
language but its use is generally discouraged. 
See http://clhs.lisp.se/Issues/iss104_w.htm for a discussion about this 
issue in Common Lisp for some background context. In short, compile time 
effects may not be captured whenever you use defining macros as non 
top-level forms. I think you're seeing something like this manifest here. 
In this case, since you referenced a var which was not installed when the 
compiler reaches the calling code, the compiler will throw this error 
message. I would suggest rethinking this because the solution is ugly, but 
you should use something like clojure.core/resolve or 
clojure.core/ns-resolve to resolve the var dynamically and then funcall it. 

On Monday, August 8, 2016 at 2:52:37 PM UTC-4, fah...@gmail.com wrote:
>
> user> (macroexpand-1 '(defn foo [x] (inc x)))
> (def foo (clojure.core/fn ([x] (inc x))))
>
> If defn is just a macro, then it seems I can do this:
>
> user> (defn bar [] (fn ([x] (inc x))))
> #'user/bar
>
> user> (def foo (bar))
> #'user/foo
>
> user> foo
> #function[user/bar/fn--10778]
>
> But the result is a little different than doing it directly with defn:
>
> user> (defn foo [x] (inc x))
> #'user/foo
>
> We had #'user/*bar/fn--10778* vs #'user/foo. But either way, foo is bound 
> to something.
>
> Is the difference significant? It seems like it is because I tried 
> something similar in my project and got the following:
>
> IllegalStateException Attempting to call unbound fn: #'p.core/default-step 
>  clojure.lang.Var$Unbound.throwArity (Var.java:43)
> p.core> default-step
> #function[p.core/make-step/fn--10747]
>
> Function default-step was def'd using make-step which returned a function 
> and default-step is bound, so why does the repl say it is not?
>
> (defn make-step [some-args]
>   (fn ([other-args]
>        (some-body using-both-args))))
>
> Basically I need to define a bunch of similar functions and am trying to 
> use another function to help define them (instead of using a macro). But it 
> seems I'm doing something wrong...
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to