This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: comparing char primitives


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]