Arc Forumnew | comments | leaders | submitlogin
Should Java method calls take precedence over lexically bound fns?
1 point by jazzdev 5310 days ago | 5 comments
In Jarc, java method calls look like regular function calls:

  (getTime (new java.lang.Date))
Global functions don't override this. The above works even if there's a getTime function defined earlier:

  (def getTime (x) (+ "" (seconds) ": " x))
This has the advantage that global functions don't need to change when new objects are introduced.

If you want the global function you have to use apply:

  (apply getTime (list (new java.util.Date))) => "1272754463: Sat May 01 ..."
In Jarc, you apply symbols to call Java methods:

  (apply 'getTime (list (new java.util.Date))) => 1272754029623
But should lexically bound functions override this?

  (def foo (getTime x)
    (... (getTime x) ...)
If lexically bound functions take precedence, then the compiler can generate faster code for functions that take a fn as an argument.

So the important question seems to be:

Is the coder likely to make a mistake and reuse a Java method name as a fn argument name without realizing it? Probably not.

Let's say I'm writing

(def xyz (foo o) (... (foo o) ...))

Then I'm pretty sure I'd always want the local foo to be applied. I can't imagine a case where I'd want some Java method named foo to be called instead.

Thoughts?



1 point by evanrmurphy 5307 days ago | link

> Is the coder likely to make a mistake and reuse a Java method name as a fn argument name without realizing it. Probably not.

If this is more or less the deciding question, then I think your decision depends on whether Jarc follows Arc's design philosophy or Java's (or some other one). That is, if it's Arc's, then go with the lexically bound fns and let them make mistakes. If it's Java's or other, then since you say it's probably not a common mistake (and I agree) then you might still go with the coder's fns, but would have to consider the opposite.

-----

1 point by jazzdev 5306 days ago | link

Jarc is designed to follow the Arc philosophy. I'm trying to get away from the Java philosophy! ;-)

Good point about Arc letting users make mistakes. Jarc shouldn't go out of its way to avoid coding mistakes, but given two choices considering which might generate less coding mistakes seems a valid consideration.

But the driver is really that I want the compiler to generate the fastest code possible. Minimizing coding mistakes is a post-hoc rationalization.

Since the compiler doesn't (currently) do any type inference, I have to make a choice.

-----

2 points by jazzdev 5307 days ago | link

Well, I've decided the answer should be no. Lexically bound fns should override Java method calls.

-----

1 point by evanrmurphy 5307 days ago | link

So will Java method calls still be possible over lexically bound fns by applying symbols, as you describe in the original post?

-----

1 point by jazzdev 5306 days ago | link

Yes.

-----