This is the mail archive of the kawa@sources.redhat.com 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]

The nature of truth


What's the relationship between Scheme booleans and Java booleans?

I understand that internally, Kawa does the equivalent of

    if (x == Boolean.FALSE)
       ...

which works fine if we're in 100% Scheme.  But I have a problem when I'm
in Scheme and call a Java method which returns a java.lang.Boolean.  In
that situation the (x == Boolean.FALSE) logic no longer works.  Why?
because the Java method is returning new Boolean( "false" ) which is not
the same object as the "interned" Boolean.FALSE object.

Is this a bug?  I truly can't decide.  I can think of (at least) three
different answers:

1.  This is a bug, Kawa should and will generate more complicated code
    to automatically do the right thing.  This has a potentially large
    performance impact.

2.  This is not a bug.  Scheme booleans are not Java Booleans.  If you
    wish to convert from one type to another use a function like:

        (define (java-boolean->boolean x)
          (define-namespace bool "class:java.lang.Boolean")
          (if (instance? x <java.lang.Boolean>)
              (bool:boolean-value x)
              (if x
                  #t
                  #f)))

3.  This is a not a bug, but as a new feature Kawa will introduce the
    magic type <Boolean> which will automatically convert to and from
    Scheme <boolean> and Java java.lang.Boolean.  Similar to the magic
    <String> type which converts Scheme and Java strings.

(In cases 2 and 3 the "boolean?" procedure will need to be changed.)

Comments?

Regards,
Chris Dean


P.S. For those not following along, here's a simple example.  All
     return values should be 'false-value.

    (if (make <java.lang.Boolean> "false") 'true-value 'false-value)
    => true-value

    (if #f 'true-value 'false-value)
    => false-value

    (if (static-field <java.lang.Boolean> 'FALSE) 'true-value 'false-value)
    => false-value



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