Validity of error on asSpreader, or, seeking alternative
Jim Laskey
jlaskey at me.com
Tue May 10 05:27:04 PDT 2011
Currently we get an "java.lang.IllegalArgumentException: Array is not of length n" error if the array being passed in does not match the array length supplied on the asSpreader call. But wouldn't a dynamic language want some flexibility there.
ex.
Suppose a language implementation chose 8 as the maximum number of args to be passed directly and any call over 8 arguments is passed as an array. (All in the name of dispatch implementation simplicity.)
def f(x, y) { ...}
f(1); // one short but can be padded with null or undef.
f(1, 2); // correct number of args.
f(1, 2, 3); // one too many, just truncate.
f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // passed as an fixed size array, need to spread over two args.
f(1, 2 | x); // passed as a variable sized array, need to spread over two args.
In the last two cases we really don't know what size may be fired at us based on call site info. All we really care about is the first two value and then discard the rest.
a) Is the asSpread runtime check too restrictive?
OR
b) Is anyone aware of a clever little trick to spread and truncate on the fly?
Cheers,
-- Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20110510/6fb000ac/attachment.html
More information about the mlvm-dev
mailing list