On Sat, Jul 30, 2011 at 1:00 AM, Petr Gladkikh <petrg...@gmail.com> wrote:
> I tried this since I have not used macroses for real problem so far.
> And it actually works.
> But I do not understand why it works.
> I have class:
> class Foo {
>    public String s;
>    public int v;
>    public String toString()  { return "{" + s + "," + v + "}"; }
> }
>
> Then in Clojure:
>  (defsetter abcde [:s :v])
>  (let [afoo (actialpackage.Foo.)]
>   (set-abcde afoo {:s "S" :v 42})
>   (println afoo))
>
> But at the moment  (defsetter abcde [:s :v]) is expanded nothing is
> known about actual class.
> So it is not clear to me why this works but giving field names at
> runtime does not.
>
> Can anyone clarify this?
> Maybe this wokrs because in this case compiler can infer type of java
> object at compile time?

The macro expands into field-accessing code. If the compiler infers
the type, this becomes fast bytecode to access the fields. Otherwise
it becomes slowish reflection calls, but still works.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

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