* Going from Scheme list to Java array
@ 2020-06-22 16:26 Duncan Mak
2020-06-22 16:58 ` Per Bothner
2020-06-23 0:02 ` Per Bothner
0 siblings, 2 replies; 9+ messages in thread
From: Duncan Mak @ 2020-06-22 16:26 UTC (permalink / raw)
To: kawa mailing list
Hello,
it doesn't look like there's a Scheme list -> Java array conversion
function, so I tried to write one modelled after the function from Clojure:
(define (into-array l ::java.util.List array-type)
(let* ((size (length l))
(array ((primitive-array-new array-type) size)))
(l:toArray array)))
(display (into-array (list 1 2 3) <int>))
When I run this in Kawa 3.1.1, this is what I see:
foo.scm:4:5: warning - more than one possibly applicable method 'toArray'
in java.util.List
candidate: Type java.lang.Object[] java.util.List.toArray(ClassType
java.util.function.IntFunction<null>)
candidate: Type java.lang.Object[]
java.util.List.toArray(java.lang.Object[])
Argument (null) to 'gnu.lists.Pair.toArray' has wrong type
at gnu.mapping.CallContext.matchError(CallContext.java:185)
at gnu.expr.GenericProc.applyToConsumerGP(GenericProc.java:132)
at gnu.mapping.CallContext.runUntilDone(CallContext.java:586)
at gnu.mapping.CallContext.runUntilValue(CallContext.java:669)
at gnu.mapping.Procedure.applyL(Procedure.java:136)
at gnu.kawa.reflect.Invoke.applyToObject(Invoke.java:198)
at gnu.mapping.CallContext.runUntilValue(CallContext.java:656)
at gnu.mapping.Procedure.apply3(Procedure.java:167)
at foo.intoArray(foo.scm:4)
at foo.intoArray$check(foo.scm:1)
at gnu.mapping.CallContext.runUntilValue(CallContext.java:656)
at gnu.mapping.Procedure.apply2(Procedure.java:160)
at foo.run(foo.scm:6)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:290)
at gnu.expr.CompiledModule.evalModule(CompiledModule.java:42)
at gnu.expr.CompiledModule.evalModule(CompiledModule.java:60)
at kawa.Shell.runFile(Shell.java:571)
at kawa.Shell.runFileOrClass(Shell.java:474)
at kawa.repl.processArgs(repl.java:710)
at kawa.repl.main(repl.java:830)
Is there a better way to write this? What's the right way to do this
conversion and should we include it into the system?
--
Duncan.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Going from Scheme list to Java array
2020-06-22 16:26 Going from Scheme list to Java array Duncan Mak
@ 2020-06-22 16:58 ` Per Bothner
2020-06-23 0:08 ` Per Bothner
2020-06-23 0:02 ` Per Bothner
1 sibling, 1 reply; 9+ messages in thread
From: Per Bothner @ 2020-06-22 16:58 UTC (permalink / raw)
To: kawa, Duncan Mak
On 6/22/20 9:26 AM, Duncan Mak via Kawa wrote:
> Hello,
>
> it doesn't look like there's a Scheme list -> Java array conversion
> function,
You can use the splicing operator along with an array constructor:
(define l1 '(df 12 (3 4) abc))
(object[] @l1)
==> [df 12 (3 4) abc]
--
--Per Bothner
per@bothner.com http://per.bothner.com/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Going from Scheme list to Java array
2020-06-22 16:26 Going from Scheme list to Java array Duncan Mak
2020-06-22 16:58 ` Per Bothner
@ 2020-06-23 0:02 ` Per Bothner
2020-06-23 0:05 ` Duncan Mak
2020-06-23 11:10 ` spellcard199
1 sibling, 2 replies; 9+ messages in thread
From: Per Bothner @ 2020-06-23 0:02 UTC (permalink / raw)
To: Duncan Mak, kawa mailing list
On 6/22/20 9:26 AM, Duncan Mak via Kawa wrote:
> (define (into-array l ::java.util.List array-type)
> (let* ((size (length l))
> (array ((primitive-array-new array-type) size)))
> (l:toArray array)))
>
> (display (into-array (list 1 2 3) <int>))
>
> When I run this in Kawa 3.1.1, this is what I see:
>
> foo.scm:4:5: warning - more than one possibly applicable method 'toArray'
> in java.util.List
> candidate: Type java.lang.Object[] java.util.List.toArray(ClassType
> java.util.function.IntFunction<null>)
> candidate: Type java.lang.Object[]
> java.util.List.toArray(java.lang.Object[])
Not sure what is going on here. When I use Java 8, there is no problem.
When I use Java 14, I get the same error. So it seems like something
got added (after Java got default interface methods). However, I don't see
it in the documentation here:
https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/util/List.html
--
--Per Bothner
per@bothner.com http://per.bothner.com/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Going from Scheme list to Java array
2020-06-23 0:02 ` Per Bothner
@ 2020-06-23 0:05 ` Duncan Mak
2020-06-23 11:10 ` spellcard199
1 sibling, 0 replies; 9+ messages in thread
From: Duncan Mak @ 2020-06-23 0:05 UTC (permalink / raw)
To: Per Bothner; +Cc: kawa mailing list
On my box, I'm running on JDK 11 on a Mac when I get the error:
$ java -version
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.7+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.7+10, mixed mode)
On Mon, Jun 22, 2020 at 8:02 PM Per Bothner <per@bothner.com> wrote:
> On 6/22/20 9:26 AM, Duncan Mak via Kawa wrote:
> > (define (into-array l ::java.util.List array-type)
> > (let* ((size (length l))
> > (array ((primitive-array-new array-type) size)))
> > (l:toArray array)))
> >
> > (display (into-array (list 1 2 3) <int>))
> >
> > When I run this in Kawa 3.1.1, this is what I see:
> >
> > foo.scm:4:5: warning - more than one possibly applicable method 'toArray'
> > in java.util.List
> > candidate: Type java.lang.Object[] java.util.List.toArray(ClassType
> > java.util.function.IntFunction<null>)
> > candidate: Type java.lang.Object[]
> > java.util.List.toArray(java.lang.Object[])
>
> Not sure what is going on here. When I use Java 8, there is no problem.
> When I use Java 14, I get the same error. So it seems like something
> got added (after Java got default interface methods). However, I don't see
> it in the documentation here:
>
> https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/util/List.html
> --
> --Per Bothner
> per@bothner.com http://per.bothner.com/
>
--
Duncan.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Going from Scheme list to Java array
2020-06-22 16:58 ` Per Bothner
@ 2020-06-23 0:08 ` Per Bothner
2020-06-23 0:28 ` Duncan Mak
0 siblings, 1 reply; 9+ messages in thread
From: Per Bothner @ 2020-06-23 0:08 UTC (permalink / raw)
To: kawa, Duncan Mak
Does using splicing+constructor seem like a goo solution to you?
On 6/22/20 9:58 AM, Per Bothner wrote:
> (define l1 '(df 12 (3 4) abc))
> (object[] @l1)
> ==> [df 12 (3 4) abc]
--
--Per Bothner
per@bothner.com http://per.bothner.com/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Going from Scheme list to Java array
2020-06-23 0:08 ` Per Bothner
@ 2020-06-23 0:28 ` Duncan Mak
2020-06-23 17:23 ` Per Bothner
0 siblings, 1 reply; 9+ messages in thread
From: Duncan Mak @ 2020-06-23 0:28 UTC (permalink / raw)
To: Per Bothner; +Cc: kawa mailing list
Yes, it works. It might be a good idea to mention java arrays explicitly in
that section of the documentation too.
I was reading these 2 pages pretty carefully when I was trying to write my
INTO-ARRAYS function:
https://www.gnu.org/software/kawa/tutorial/Sequences.html
https://www.gnu.org/software/kawa/Array-operations.html
Duncan.
On Mon, Jun 22, 2020 at 8:08 PM Per Bothner <per@bothner.com> wrote:
> Does using splicing+constructor seem like a goo solution to you?
>
> On 6/22/20 9:58 AM, Per Bothner wrote:
> > (define l1 '(df 12 (3 4) abc))
> > (object[] @l1)
> > ==> [df 12 (3 4) abc]
>
>
>
> --
> --Per Bothner
> per@bothner.com http://per.bothner.com/
>
--
Duncan.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Going from Scheme list to Java array
2020-06-23 0:02 ` Per Bothner
2020-06-23 0:05 ` Duncan Mak
@ 2020-06-23 11:10 ` spellcard199
2020-06-23 17:34 ` Per Bothner
1 sibling, 1 reply; 9+ messages in thread
From: spellcard199 @ 2020-06-23 11:10 UTC (permalink / raw)
To: Per Bothner; +Cc: Duncan Mak, kawa mailing list
Hello. I tried looking it up (just out of curiosity) and it seems that
the method...
> candidate: Type java.lang.Object[] java.util.List.toArray(ClassType
> java.util.function.IntFunction<null>)
... has been added between Java 8 and Java 11:
- https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html
- https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Collection.html
How I found it: I used my Java IDE's "jump to definition" from a Java
project that has Kawa's Java API as a dependency, with the cursor over
".toArray":
gnu.lists.LList l = gnu.lists.LList.makeList(new ArrayList());
java.util.function.IntFunction f = (int x) -> null;
l.toArray(f);
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Tuesday, June 23, 2020 2:02 AM, Per Bothner <per@bothner.com> wrote:
> On 6/22/20 9:26 AM, Duncan Mak via Kawa wrote:
>
> > (define (into-array l ::java.util.List array-type)
> > (let* ((size (length l))
> > (array ((primitive-array-new array-type) size)))
> > (l:toArray array)))
> > (display (into-array (list 1 2 3) <int>))
> > When I run this in Kawa 3.1.1, this is what I see:
> > foo.scm:4:5: warning - more than one possibly applicable method 'toArray'
> > in java.util.List
> > candidate: Type java.lang.Object[] java.util.List.toArray(ClassType
> > java.util.function.IntFunction<null>)
> > candidate: Type java.lang.Object[]
> > java.util.List.toArray(java.lang.Object[])
>
> Not sure what is going on here. When I use Java 8, there is no problem.
> When I use Java 14, I get the same error. So it seems like something
> got added (after Java got default interface methods). However, I don't see
> it in the documentation here:
> https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/util/List.html
>
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> --Per Bothner
>
>
> per@bothner.com http://per.bothner.com/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Going from Scheme list to Java array
2020-06-23 0:28 ` Duncan Mak
@ 2020-06-23 17:23 ` Per Bothner
0 siblings, 0 replies; 9+ messages in thread
From: Per Bothner @ 2020-06-23 17:23 UTC (permalink / raw)
To: Duncan Mak; +Cc: kawa mailing list
On 6/22/20 5:28 PM, Duncan Mak wrote:
> Yes, it works. It might be a good idea to mention java arrays explicitly in that section of the documentation too.
I added some notes:
https://gitlab.com/kashell/Kawa/-/commit/e85ee67cfb5a4289dffb21b2421f41a1944d31ca
--
--Per Bothner
per@bothner.com http://per.bothner.com/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Going from Scheme list to Java array
2020-06-23 11:10 ` spellcard199
@ 2020-06-23 17:34 ` Per Bothner
0 siblings, 0 replies; 9+ messages in thread
From: Per Bothner @ 2020-06-23 17:34 UTC (permalink / raw)
To: spellcard199; +Cc: Duncan Mak, kawa mailing list
On 6/23/20 4:10 AM, spellcard199 wrote:
> Hello. I tried looking it up (just out of curiosity) and it seems that
> the method...
>
>> candidate: Type java.lang.Object[] java.util.List.toArray(ClassType
>> java.util.function.IntFunction<null>)
>
> ... has been added between Java 8 and Java 11:
>
> - https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html
> - https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Collection.html
Now I see it - not sure why I didn't see it before. Thanks.
(I'm spending a lot less time with Java these days.)
--
--Per Bothner
per@bothner.com http://per.bothner.com/
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-06-23 17:34 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-22 16:26 Going from Scheme list to Java array Duncan Mak
2020-06-22 16:58 ` Per Bothner
2020-06-23 0:08 ` Per Bothner
2020-06-23 0:28 ` Duncan Mak
2020-06-23 17:23 ` Per Bothner
2020-06-23 0:02 ` Per Bothner
2020-06-23 0:05 ` Duncan Mak
2020-06-23 11:10 ` spellcard199
2020-06-23 17:34 ` Per Bothner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).