On Mon, Aug 1, 2011 at 8:54 AM, Dmitry Gutov <raa...@gmail.com> wrote:
> On Aug 1, 1:32 pm, Brian McKenna <puffnfr...@gmail.com> wrote:
>> For anyone else with the same problem, I just found the nice way to do it:
>>
>>     (def iframe (. field (getEditableIframe)))
>
> This should be equivalent to (def iframe (.getEditableIframe field))
> which is the usual way to do method calls on the host language objects.

In Clojure you are correct, as that is unambiguous on the JVM.
However, in JavaScript the meaning of that expression is ambiguous and
so ClojureScript always treats (.foo bar) as *field* access, not a
method call.  So in the above example, iframe will be equal to the
*function* getEditableframe.

There are two options if you want to call a method with no arguments:
1. (. obj (method))  ; As shown by Brian above
2. (.method obj ())

They're both ugly, but valid syntax in Clojure and ClojureScript.
Actually, style (1) is "classic" Clojure and used to be the only word
order for doing host method calls.

Anyway, Rich has expressed a preference for style (1).

I'm personally ambivalent -- I might prefer the potential of someone
reading to code mistakenly thinking () is an empty list to them
thinking that (method) is a normal function call.  Actually, I'm still
hoping we'll be able to come up with something less ugly that is
nevertheless consistent with normal Clojure syntax.  I have no idea
what that would be.

--Chouser

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