-
Notifications
You must be signed in to change notification settings - Fork 16
CLR Interop
CLR interop is essentially the same as JVM interop. All the basic functions for interop mentioned on http://clojure.org/java_interop work as advertised. This includes all of
- 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*)
Most of the array interop functions work.
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:
bean
parse
The proxy
function is especially useful in JVM-land to create listeners and the like. In CLR-land, we need delegates. We have added a gen-delegate
macro to assist in creating delegates. Here is a sample use:
(.add_Click button
(gen-delegate EventHandler [sender args]
(let [c (Double/Parse (.Text tb)) ]
(.set_Text f-label (str (+ 32 (* 1.8 c)) " Fahrenheit")))))
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. This is high priority item.
CLR supports true multi-dimensional arrays in addition to the ragged arrays that the JVM supports. Some extensions need to be defined.
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. This is a high-priority item.