Hi,
This is my first post to the clojure-dev list, and now my CA is
'on-file', I'll start with a thank you for all the great work that's
gone into making clojure such a fun environment to play around in. I'm
hoping to be able to contribute back something to make it even better.
I wonder if anyone has any comments/observations on the following:
A few weeks ago I posted to the clojure list about a missing feature
in gen-class[1], namely that you can't create classes with varargs
methods.
It turns out that you need to set an extra flag on the method in the
generated bytecode and ensure that the last parameter is an array. The
flag is defined in clojure.asm.Opcodes but never used.
I created a patch (attached) that allows you to mark a method with
something like this:
(ns foo
(:gen-class
:name Foo
:init init
:constructors {^:varargs ["[Ljava.lang.String;"] []}
:methods [^:varargs [foo ["[Ljava.lang.String;"] void]])
)
The patch is pretty simple and hopefully not too contentious.
In my opinion, using meta-data to specify the varargs-i-ness of a
method is a bit flaky. For example what should happen if you specify
:varargs but don't have a suitable method signature? There's a good
chance of error, which I'm not too happy with.
Since clojure already has 'rest' args' it makes sense to me to use
that syntax, which would lead to something like this..
(ns foo
(:gen-class
:name Foo
:init init
:constructors { [ & java.lang.String ] [] }
:methods [ [foo [ & java.lang.String ] void] ])
)
(I'd expect to make this also work for primitives)
This is a more significant change and the gen-class code is quite
complex (as least for me), so before I start hacking I thought I'd
throw the idea out there for feedback.
Any thoughts?
regards
Neale
{t: @sw1nn, w:
sw1nn.com }
[1]
https://groups.google.com/d/topic/clojure/HMpMavh0WxA/discussion