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]

Re: The nature of truth


Jim White <jim@pagesmiths.com> wrote:
> I don't have any problem putting the onus on the Java code (or the
> Scheme application wrapper) to convert that result properly.

Agreed.  

It does, however, seems like the kind of problem where the same type of
bug could be created over and over again.  I'd like to say loud and
clear in the docs that Kawa behaves in such-and-such a manner and the
Scheme application code must be prepared for that behavior.

> Kawa is slightly inconsistent with #f:
>  ...

Exactly.  Another cut is:

    (let ((x (make <java.lang.Boolean> "false")))
      (format #t "Am I a boolean? ~A~%" (boolean? x))
      (format #t "I think I'm ~S~%" x)
      (format #t "But \"if\" says I am a ~A~%" (if x 'true-value 
                                                     'false-value)))
=>

    Am I a boolean? #t
    I think I'm #f
    But "if" says I am a true-value

A small patch might be appropriate to help with this inconsistency.  A
sample patch is below, just to convey the idea.  (I haven't checked it
carefully.)

Regards,
Chris Dean


Index: gnu/kawa/functions/DisplayFormat.java
===================================================================
RCS file: /cvs/kawa/kawa/gnu/kawa/functions/DisplayFormat.java,v
retrieving revision 1.9
diff -u -r1.9 DisplayFormat.java
--- gnu/kawa/functions/DisplayFormat.java	6 Apr 2003 05:33:22 -0000	1.9
+++ gnu/kawa/functions/DisplayFormat.java	20 Jul 2003 01:42:32 -0000
@@ -93,8 +93,8 @@
 
   public void writeObject(Object obj, Consumer out)
   {
-    if (obj instanceof Boolean)
-      writeBoolean(((Boolean)obj).booleanValue(), out);
+    if (obj == Boolean.FALSE || obj == Boolean.TRUE)
+      writeBoolean( obj != Boolean.FALSE, out);
     else if (obj instanceof Char)
       writeChar(((Char)obj).charValue(), out);
     else if (obj instanceof Character)
Index: kawa/lib/misc.scm
===================================================================
RCS file: /cvs/kawa/kawa/kawa/lib/misc.scm,v
retrieving revision 1.24
diff -u -r1.24 misc.scm
--- kawa/lib/misc.scm	31 May 2003 01:39:55 -0000	1.24
+++ kawa/lib/misc.scm	20 Jul 2003 01:42:32 -0000
@@ -7,7 +7,7 @@
 |#
 
 (define (boolean? x)
-  (instance? x <java.lang.Boolean>))
+  (or (eq? x #t) (eq? x #f)))
 
 (define (symbol? x)
   (instance? x <java.lang.String>))


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