Hi!

(I'm new to this list so i hope this isn't old stuff)



In Jess42, for some reason i needed to call functions with null-values
from jess.
So, I noticed that in  ReflectFunctions.java in valueToObject()
the test if an atom correspnds to a java-null value is:

            else if (!clazz.isPrimitive() && s.equals("NIL"))
            return null;

Whereas when the null-values are converted to atoms in
Funcall.java as

        s_nil = new Value("nil",RU.ATOM);

This causes the following behavior:

(defglobal ?*v* = (new java.util.Vector))
(call ?*v*  addElement NIL)
(eq NIL (call ?*v*  firstElement))
;; returns false, but
(eq nil (call ?*v*  firstElement))
;; returns true


If one wants the current behavior, that both jess-strings and -atoms
with value
nil should be converted to java-null I guess the valueToObject line
could be changed to

            else if (!clazz.isPrimitive() &&
s.equals(Funcall.NIL().toString())

or if it's sufficient that atoms can have null-values   one could write

            else if (!clazz.isPrimitive() && value.equals(Funcall.NIL())

I'll do the second alternative in my private copy. Since atoms and
strings
are not equal anyway, i.e.

Jess> (eq a "a")
FALSE
Jess> (eq nil "nil")
FALSE

I wonder if you have any comments on this patch. Could this be changed
in future release?



One more thing. I am thinking about adding automatic conversion of atoms
to java-strings
at appropriate places. I.e, in my opinion it would be nice to it would
be nice to be able to do:

(call  (new java.lang.Vector) addElement foo)

where foo would be converted to a string. This might be a bad idea, but
i would be
very interested in your opinion.   The patch  in objectToValue would be

   else if (clazz.isAssignableFrom(s.getClass()))
       return s;

The problem is here that java.lang.Strings are not converted back to
jess-strings, i.e.

(defglobal ?*v* = (new java.util.Vector))
(call ?*v*  addElement "nil")
(call ?*v*  firstElement)
;;<External-Address:java.lang.String>
(eq "nil" (call ?*v*  firstElement) )
;; returns false
(eq "nil" (call (call ?*v*  firstElement) toString))
;;returns true

And the back conversion would be ambiguos (atom OR string?).
Perhaps one could decide that only strings would be automatically
converted?
For automatic java-string -> jess-string conversion one would have to
patch
Value in different places, equals, toString etc... This would probably
cause some
larger changes that one would have to think more about.

So what do you think? Is a closer connection between  java-string and
jess-strings
a bad idea? One can do without them and perhaps it's better to keep a
distinct
separation between jess's and java's  type-systems..


regards,

    andreas rasmusson






---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------

Reply via email to