public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Duncan Mak <duncanmak@gmail.com>
To: kawa mailing list <kawa@sourceware.org>
Subject: Going from Scheme list to Java array
Date: Mon, 22 Jun 2020 12:26:05 -0400	[thread overview]
Message-ID: <CABgWrqqYk5620G06mypC7vDTrqp=GE6E=WKoX7hUxMMjUZXqpA@mail.gmail.com> (raw)

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.

             reply	other threads:[~2020-06-22 16:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-22 16:26 Duncan Mak [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABgWrqqYk5620G06mypC7vDTrqp=GE6E=WKoX7hUxMMjUZXqpA@mail.gmail.com' \
    --to=duncanmak@gmail.com \
    --cc=kawa@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).