This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: building int[] arrays at runtime


On 02/01/2017 03:12 PM, Peter Lane wrote:
If I build an int[] at runtime, I get a warning about more than one applicable method.  The code seems to run and give the right result, so the runtime does the right thing.  As the warning always appears first, when the script is loaded, I assume the script is compiled on loading and so the problem is discovered.

I understand why I'm getting this warning, but wondered if:

a. I should do something other than (apply int[] (list 3)) to create an int[] at runtime

Yes, use the '@' splice operator:

(*x*:show (int[] @(list 3)))

This doesn't seem to be documented in the release manual, but it is documented
in the documentation for the "invoke" development branch:

http://per.bothner.com/kawa/invoke/#Application-and-Arguments-Lists
http://per.bothner.com/kawa/invoke/#Primitive-expression-syntax.idm140044326562704

(But note a bunch of this stuff doesn't work in the release or the master branch.
However, the splice operator '@' does work.)

b. Can I put a compile-time type hint in, to appease/suppress the initial checks?

Use the 'as' special function:

(*x*:show (as int[] (apply int[] (list 3))))

That's basically a type cast.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]