On Jan 25, 5:27 pm, Chouser <chou...@gmail.com> wrote:
> On Sun, Jan 25, 2009 at 8:01 AM, Chouser <chou...@gmail.com> wrote:
> > On Sun, Jan 25, 2009 at 7:06 AM, Anand Patil
> > <anand.prabhakar.pa...@gmail.com> wrote:
>
> >> I'd like to repeat my request for an example of definline usage; I
> >> feel I've tried everything.
>
> > I looked into this yesterday, and it seems to me that definline has
> > been broken since SVN rev 1065.  I don't know why the usages of it in
> > core.clj don't cause errors at compile time, but they don't seem to
> > work quite right.
>
> I wrote a new definline that seems to work correctly:
>
> (defmacro definline
>   "Experimental - like defmacro, except defines a named function whose
>   body is the expansion, calls to which may be expanded inline as if
>   it were a macro. Cannot be used with variadic (&) args."
>   [name & decl]
>   (let [[pre-args [args expr]] (split-with (comp not vector?) decl)]
>     `(do
>        (defn ~name ~...@pre-args ~args ~(apply (eval (list `fn args expr)) 
> args))
>        (alter-meta! (var ~name) assoc :inline (fn ~args ~expr))
>        (var ~name))))
>
> Using definline work, and return the Var, just like defn does:
> user=> (definline inc2 "returns x plus 2" [x] `(+ 2 ~x))
> #'user/inc2
>

Terrific, thanks very much!

Anand


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