public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: "Sudarshan S Chawathe" <chaw@eip10.org>
To: Duncan Mak <duncanmak@gmail.com>
Cc: Jamison Hope <jhope@alum.mit.edu>,
	"kawa@sourceware.org" <kawa@sourceware.org>
Subject: Re: Working with string keys in a java.util.Map
Date: Sat, 04 Jul 2020 00:29:31 -0400	[thread overview]
Message-ID: <13148.1593836971@localhost> (raw)
In-Reply-To: Your message of "Sat, 04 Jul 2020 00:04:39 -0400." <CABgWrqoNGRKe=raFS4gm=AjmOcmgczCqTO979QH8CdfNdWfT-A@mail.gmail.com>

This is only my personal preference but, for what it's worth, I prefer
not having special syntax for such things.  I think my earlier message
may have inadvertently suggested that I thought having to write (String
"foo") to get a Java String is a burden; in reality I think it is quite
reasonable.

What I often do is define interface procedures between my code and
whatever Java library I am using and declare the arguments of those
procedures with type annotations (String, in this case) and then Kawa
takes care of the conversion from Kawa string to Java String when I
invoke the procedure.  And Kawa's type checking is handy in catching my
errors too, as an added benefit.

Regards,

-chaw

> Date: Sat, 4 Jul 2020 00:04:39 -0400
> Subject: Re: Working with string keys in a java.util.Map
> To: Jamison Hope <jhope@alum.mit.edu>
> From: Duncan Mak via Kawa <kawa@sourceware.org>
> Reply-To: Duncan Mak <duncanmak@gmail.com>
> Cc: "kawa@sourceware.org" <kawa@sourceware.org>
> 
> 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-int=
> erpolation
> 
> Gauche's design look quite nice:
> 
> #"This is Gauche, version ~(gauche-version)."
>  =E2=87=92 "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 =E2=80=9Cowner=E2=80=9D) ought to work with the literal c=
> onverted 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 Ma=
> p
> > > 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
> >
> 
> 
> --=20
> Duncan.
> 
> 

  reply	other threads:[~2020-07-04  4:29 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
2020-07-04  4:29         ` Sudarshan S Chawathe [this message]
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=13148.1593836971@localhost \
    --to=chaw@eip10.org \
    --cc=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).