[CLJ-1188] Public Java API Created: 30/Mar/13 Updated: 12/Apr/13 Resolved: 12/Apr/13
|Fix Version/s:||Release 1.6|
|Reporter:||Stuart Halloway||Assignee:||Stuart Halloway|
|Attachments:||CLJ-1188.patch CLJ-1188-via-var-intern.patch CLJ-1188-wrapper-free.patch|
|Patch:||Code and Test|
Problem: Java consumers need an API into Clojure that does not drag in a ton of concrete implementation detail.
Solution: Very small API class that allows looking up Vars (returning IFn), and reading data (as edn). Uses Clojure logic where possible, e.g. Var.intern.
|Comment by Kevin Downey [ 02/Apr/13 11:34 AM ]|
the attached patch would turn
in to something like
what is the value of VRefs over using Vars directly?
|Comment by Kevin Downey [ 02/Apr/13 5:56 PM ]|
using this from a java api, it looks like if the namespace the var is in is not loaded when you go to create a VRef it will return null, generally my java code that calls clojure looks something like
can you tell me without checking the java/jvm spec if FOO is null? does the static init block run before or after static fields are init'ed? returning null just seems like a bad idea.
|Comment by Stuart Halloway [ 03/Apr/13 6:53 AM ]|
Per discussion on the ticket and with Rich, the wrapper-free approach (Apr 3 patch) is preferred.
|Comment by Stuart Halloway [ 03/Apr/13 7:03 AM ]|
The purpose of not returning Vars is outlined in the design discussion. That said, it is possible to return IFn, which does not drag in too much implementation detail (just a javadoc config tweak, see
Java static initializers run in lexical order, and I trust Java programmers to know Java.
I can think of several options other than returning null when a var is not available, and they are all complecting, inconsistent with Clojure, or both.
|Comment by Kevin Downey [ 03/Apr/13 12:08 PM ]|
Always returning the var is very consistent with clojure, it is what RT.var does. It is what the var lookups emitted by the compiler do. RT.var is most likely the point through which most java that calls clojure goes at the moment.
As to "hiding" vars, how about creating a clojure.lang.ILink interface with both deref() and fn(), have Var implement it. The previous discussion I see linked all seems to presume hiding Var without discussion of why it should be hidden. What I see Rich saying is:
It seems like Rich is suggesting that ILink or whatever should also bring in IFn, but I wonder if having a fn() that does the cast for you is an acceptable alternative to that.
|Comment by Rich Hickey [ 12/Apr/13 8:24 AM ]|
The API should be called var, not fn, and should return IFn. Also, I really want the logic of RT.var (i.e. Var.intern) to be used, not this new logic. Please find another way to handle the string/symbol support.