This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Strings and Characters in Kawa
- From: Nigel Dolby <nigel_dolby at acm dot org>
- To: 'Kawa List' <kawa at sources dot redhat dot com>
- Date: Mon, 30 Jan 2006 09:21:04 -0600
- Subject: Strings and Characters in Kawa
In porting my Common Lisp code to Kawa I have encountered a few problems
with string- and character-handling, and would like to understand where
the problems come from and how to address them.
The Java and Scheme functionality overlaps in these areas, so one has to
choose whether to employ Java strings or Scheme strings. On the basis
that Java is a more elementary level of functionality than Scheme and
has quite rich string-handling capabilities which should be fairly
efficient, it seems appropriate to use Java strings.
But if I try to give a Java string to a Scheme function that expects a
string I get a type error. Similarly, if I try to give a Scheme
character to a Java function that expects a character, the function
fails (with no error message).
The following Kawa forms exhibit these problems. The code is intended to
accept a line of text from an input file, represented here by making a
Java string, to locate the first space in the line, and then to create a
Kawa symbol from the characters prior to the space.
(set! jstr (make <java.lang.String> "DOMAIN Some Name"))
(set! sppos (invoke jstr 'indexOf #\space))
[fails, but replacing #\space by 32 works, correctly returning 6]
(set! typesymb (string->symbol (invoke jstr 'substring 0 sppos)))
[generates type error]
I would like to understand exactly what is (or is not?) going on, and
how to convert strings and characters between Java and Kawa and vice
versa (or perhaps how to avoid any need for conversion). It would also
be interesting to know whether there are reasons favoring use of Scheme
strings/characters or Java strings/characters in Kawa (although some
amount of conversion is probably inevitable). Thanks.
Nigel Dolby.