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