This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: comparing char primitives
- From: Per Bothner <per at bothner dot com>
- To: Jamison Hope <jrh at theptrgroup dot com>
- Cc: Kawa mailing list <kawa at sourceware dot org>
- Date: Thu, 16 Feb 2012 16:59:09 -0800
- Subject: Re: comparing char primitives
- References: <1FB50EC3-E16B-44A0-BE60-9A3D25C158DA@theptrgroup.com>
On 02/16/2012 04:05 PM, Jamison Hope wrote:
Hello,
I'm looking to see if there's a way to compare char primitives
directly, as in
boolean javaCharEq(char c1, char c2) { return c1 == c2; }
...
Am I correct in concluding that currently there is no way to compare
unboxed chars? It looks like that's also the case for boolean.
The following seems to work:
(define (eqc (c1::char) (c2::char))
(let ((i1 ::int c1) (i2 ::int c2))
(= i1 i2)))
Optimizing char=? etc might be a reasonable thing to do, and
not that difficult.
Complicating things is a bit is there is no primitive type
corresponding to (32-bit or at least 20-bit) Unicode character
- we have to use int. At least not in Java. No reason we couldn't
add one in Kawa. I.e. we could define a "character" type that is
implemented as int, but boxes to gnu.text.Char. A similar mechanism
could be used to implement signed number types, e.g. "signed-int".
Or more generally any final class with a single immutable field.
It's something I've been warning to do - but haven't had time for.
An extension of LangPrimType might be a good start, though that
has some issues with conversions.
--
--Per Bothner
per@bothner.com http://per.bothner.com/