From: Jamison Hope <jhope@alum.mit.edu>
To: "kawa@sourceware.org" <kawa@sourceware.org>
Subject: Re: Working with string keys in a java.util.Map
Date: Fri, 3 Jul 2020 21:30:59 -0400 [thread overview]
Message-ID: <CA+ghDQ_mhy+EcNt3PpOCB8rmx__abZFO8RHvXmX7x-S+jc+pHA@mail.gmail.com> (raw)
In-Reply-To: <68f1a45a-173d-aa66-298e-599c37cd93dc@bothner.com>
In this case, I think another option is to define a wrapper function that
specifies the argument type as String, like:
(define (get attrs key::String) (attrs:get key))
Then (get attrs “owner”) ought to work with the literal converted to
java.lang.String.
-J
On Fri, Jul 3, 2020 at 6:33 PM Per Bothner <per@bothner.com> wrote:
> On 7/3/20 2:52 PM, Sudarshan S Chawathe wrote:
> > I've had to get Java "String"s from Kawa strings often for similar
> > reasons when using other JVM libraries, etc., and I have just used
> > '(String "kawa string)'; it seems to work well, although it does
> > introduce clutter.
>
> I don't see how to avoid that in general. One could write a wrapper Map
> that uses a coercion function to convert the key to required type,
> similar to the coercion function in the make-parameter function.
>
> Another way is to call the toString method, since Kawa strings
> implement java.lang.CharSequence:
> ("kstring":toString)
>
> This is cheap if the Kawa string is an IString, since uses a
> java.lang.String.
>
> Alternative syntax:
>
> (->java.lang.String "kstring")
> or shorter:
> (->String "kstring")
> --
> --Per Bothner
> per@bothner.com http://per.bothner.com/
>
--
Jamison Hope
next prev parent reply other threads:[~2020-07-04 1:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-03 21:46 Duncan Mak
2020-07-03 21:52 ` Sudarshan S Chawathe
2020-07-03 22:33 ` Per Bothner
2020-07-04 1:30 ` Jamison Hope [this message]
2020-07-04 4:04 ` Duncan Mak
2020-07-04 4:29 ` Sudarshan S Chawathe
2020-07-04 5:24 ` 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=CA+ghDQ_mhy+EcNt3PpOCB8rmx__abZFO8RHvXmX7x-S+jc+pHA@mail.gmail.com \
--to=jhope@alum.mit.edu \
--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).