> user=> (macroexpand-1 '(memfn add x y))
> (clojure.core/fn [target__4193__auto__ x y] (. target__4193__auto__  
> (add x y)))
>
> That is, basically (fn [object x y] (.add object x y)).

.add is macroexpanded into the more general dot form, as shown in the  
memfn expansion.

user=> (read-string "(.foo bar)")
(.foo bar)
user=> (macroexpand-1 *1)
(. bar foo)

http://clojure.org/java_interop#dot


> (doc .add) throws an exception rather than recognizing it as a  
> special form

doc looks up the docstring of a var. If the argument isn't a var, it  
will throw an exception.

If you break your contract with Clojure and make a var with a dot-name  
anyway, doc will work:

user=> (def .add 5)
#'user/.add
user=> (doc .add)
-------------------------
user/.add
nil
   nil
nil

> or similarly, though you also get strange errors if you try to  
> use .add as a variable name.)

"Symbols beginning or ending with '.' are reserved by Clojure.".

http://clojure.org/reader

You don't get errors if you use .add as a var or the name of a symbol  
(see above), though you're disobeying the docs.

You do get an error if you use it as the name of a local binding symbol:

user=> (let [.foo 5])
java.lang.ClassFormatError: Illegal field name ".foo" in class user 
$eval__10 (NO_SOURCE_FILE:0)

When you think about what this is actually doing in terms of Java  
classes, this message makes sense.

-R

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