Skip to content
dmiller edited this page Sep 13, 2010 · 12 revisions

CLR interop is essentially the same as JVM interop. All the basic functions for interop

  • Member access
    • (.instanceMember instance args*)
    • (.instanceMember Classname args*)
    • (Classname/staticMethod args*)
    • Classname/staticField
  • Dot special form
    • (. instance-expr member-symbol)
    • (. Classname-symbol member-symbol)
    • (. instance-expr (method-symbol args*)) or
    • (. instance-expr method-symbol args*)
    • (. Classname-symbol (method-symbol args*)) or
    • (. Classname-symbol method-symbol args*)
  • Instantiation
    • (Classname. args*)
    • (new Classname args*)
  • Assignment
    • (set! (. instance-expr instanceFieldName-symbol) expr)
    • (set! (. Classname-symbol staticFieldName-symbol) expr)
  • Miscellaneous
    • (.. instance-expr member+)
    • (.. Classname-symbol member+)
    • (doto instance-expr (instanceMethodName-symbol args*)*)
    • (instance? Class expr)
    • (memfn method-name arg-names*)

mentioned on http://clojure.org/java_interop work as advertised.

Most of the array interop functions work, with the exception of make-array and to-array-2d. See below.

Coercion, type hints, reflection warnings all work. (There needs to be more investigation into code generation to make sure the compiler is doing all it can.)

The things not implemented yet:

  • make-array
  • to-array-2d
  • bean
  • proxy
  • parse

All that is good, but there are areas that still need work.

Generics

The JVM version can ignore generics. The CLR version cannot. We do not have a good way of referring to generics in the forms above that reference types.

Multi-dimensional arrays

CLR supports true multi-dimensional arrays in addition to the ragged arrays that the JVM supports. The forms that reference and create arrays need to be looked at.

Assemblies

The JVM works with class files found directories and JAR files on the classpath. We have substituted the environment variable clojure.load.path as a mechanism for providing the set of directories to probe when looking for CLJ scripts and compiled-from-CLJ assemblies to load.

Not dealt with is the proper reference of types with fully-qualified assembly names.

CLJ script dual loading

Right now, we have to hand-edit files such as core.clj, core_print.clj, main.clj, etc. in order to get them to load in the JVM. These files contain many JVM-specific references that must be edited to mention BCL classes or classes in the ClojureCLR runtime such as clojure.lang.RT.

We need a better approach.