bjconlan <[email protected]> writes:
> Thanks for your quick responses. I guess having clojure behave this
> way is obvious and consistent (with having to explicitly fill in the
> vararg).
Java varargs parameters are only syntax sugar.
class SomeClass {
static int foo(String... x) {...}
}
becomes
foo(String[] x)
in the compiled byte-code.
> Sometimes I forget that Java does things that are syntactically 'nice'
> but otherwise unexpected which often isn't ideal to emulate in other
> languages... but I have mixed thoughts if this is actually the best
> stance in this case.
I think, that's the only sane way. Well, it should be doable to make
the clojure compiler implement this syntax sugar as well, so that you
could call
(SomeClass/foo "foo" "bar" "baz")
java.lang.reflect.Method has an isVarArgs() method that could be used to
determine if a method's last parameter is a varargs one. In that case,
an implicit array creation could be compiled into the call.
While this would work for a call to a static method as shown above, it
would not do the trick for non-static varargs methods, because in
(.bar my-object "foo" "bar" "baz")
the type of my-object is not available at compile-time, and thus the
varargs-check plus the possibly needed array creation would need to be
done at runtime.
Bye,
Tassilo
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en