Calling class methods

18 views
Skip to first unread message

Leo Franchi

unread,
Oct 23, 2012, 2:30:30 PM10/23/12
to clojure...@googlegroups.com
Hello folks,

Another quick question to make sure i'm not chasing a red herring… I'm trying to call a python @classmethod from an imported module. I'd like to do something like this:

(. clojure.lang.mymodule.MyClass (myClassMethod arg1 arg2 arg3))

It looks like that doesn't work right now in clojure-py, and I'm not entirely sure if that's because it's simply missing the implementation, if it's because I'm Doing It Wrong, or if it's because I'm not understanding what incantation I need. This syntax works fine for methods declared in the top-level of the module (ala clojure.lang.RT or rt.py), but there's no support that I can see for detecting if the first item in the dot syntax is a class in a module, and executing the class method from the class if it exists.

Is this a valid issue? I probably can't take a crack at it now, but would appreciate knowing if I am on the right path at least :)

cheers,
leo

Antony Lee

unread,
Oct 23, 2012, 6:34:58 PM10/23/12
to clojure...@googlegroups.com
Hi,

This works:

(.classmethodname path.to.module/ClassName)

Fully dotted names ("path.to.module.ClassName") do not exist in
clojure; what you have is ns-qualified symbols: "name.space/name". This
is somwhat infortunate on the python side of things as modules are
first-class objects in python and in an python expression such as
"path.to.module.ClassName", the last dot is no different from the
others. I don't know java at all (or barely) but I doubt this is the
case for clojure namespaces, which is why both dots and slashes are
used (and that has been kept in clojure-py).

Not sure about what you mean for "methods declared in the toplevel of a
module"? Can you clarify?

Best,

Antony
Reply all
Reply to author
Forward
0 new messages