From: Duncan Mak <duncanmak@gmail.com>
To: Jamison Hope <jhope@alum.mit.edu>
Cc: "kawa@sourceware.org" <kawa@sourceware.org>
Subject: Re: Working with string keys in a java.util.Map
Date: Sat, 4 Jul 2020 00:04:39 -0400 [thread overview]
Message-ID: <CABgWrqoNGRKe=raFS4gm=AjmOcmgczCqTO979QH8CdfNdWfT-A@mail.gmail.com> (raw)
In-Reply-To: <CA+ghDQ_mhy+EcNt3PpOCB8rmx__abZFO8RHvXmX7x-S+jc+pHA@mail.gmail.com>
What do you think of having literal syntax for this -- what about $"this is
a java string"?
This is kinda inspired by what Scala did a little while again:
https://docs.scala-lang.org/overviews/core/string-interpolation.html
Looks like Gauche decided to do something similar:
https://practical-scheme.net/gauche/man/gauche-refe/Strings.html#String-interpolation
Gauche's design look quite nice:
#"This is Gauche, version ~(gauche-version)."
⇒ "This is Gauche, version 0.9.9."
On Fri, Jul 3, 2020 at 9:31 PM Jamison Hope <jhope@alum.mit.edu> wrote:
> 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
>
--
Duncan.
next prev parent reply other threads:[~2020-07-04 4:05 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
2020-07-04 4:04 ` Duncan Mak [this message]
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='CABgWrqoNGRKe=raFS4gm=AjmOcmgczCqTO979QH8CdfNdWfT-A@mail.gmail.com' \
--to=duncanmak@gmail.com \
--cc=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).