Rostislav and Cedric – I cannot supply my own version of defn; the
macro should work with the regular clojure.core/defn.

Thomas – Your example works well with Clojure 1.2.x but doesn't with
Clojure 1.3 and 1.4. As you rightly said, &env should not be relied
upon. :)

Shantanu

On Mar 29, 4:17 am, Cedric Greevey <cgree...@gmail.com> wrote:
> On Wed, Mar 28, 2012 at 3:30 PM, Rostislav Svoboda
>
>
>
>
>
>
>
>
>
> <rostislav.svob...@gmail.com> wrote:
> >> Steve – Your example is already compact, but maybe it can be made even
> >> cheaper by specifying maxDepth of 1:
> >>http://docs.oracle.com/javase/6/docs/api/java/lang/management/ThreadM...,
> >> int)
>
> > @Shantanu: What about the defn0 macro from Steve:
>
> > (defmacro defn0 [name & fdcls]
> >  `(let [~'%0 (symbol (name (ns-name *ns*)) (name '~name))]
> >    (defn ~name ~@fdcls)))
>
> > (defn0 foo [a b]
> >    (println "Running function"%0 ":" (+ a b)))
>
> > user=> (foo 1 2)
> > Running function user/foo : 3
> > nil
>
> > Is't it what do you need?
>
> He wants to be able to use plain defn, which suggests
>
> (defmacro defn [name & other-args]
>   `(let [~'current-fn '~name]
>      (clojure.core/defn ~name ~@other-args)))
>
> ...
>
> (defn foo [x y]
>   (println current-fn)
>   (+ x y))
>
> user=> (foo 3 4)
> foo
> 7
> user=>

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

Reply via email to