Re: [classad-users] c++ & java inconsistency


Date: Fri, 6 Jun 2003 08:23:13 -0500 (CDT)
From: Alessandro Maraschini <alessandro.maraschini@xxxxxxxxxx>
Subject: Re: [classad-users] c++ & java inconsistency
Alain Roy wrote:
>As you can see the use of parentesys is different,
I don't know wheter it
>has been fixed in the latest java release but if not, can you please
check it?
>
>BTW, which should be the right representation ? (I guess it's the
second
>one but... never know..)
Both are correct representations--what problem does it cause you that
they
are different?
Java decides where the parentheses should go, regardless of what the
user
does. C++ preserves the parentheses as the users puts them in. Both
of
these have advantages and disadvantages, but it's not clearly correct
or
incorrect in either case.
We have talked about making the parentheses the same between Java and
C++,
but we have not yet done so. I believe there are ways to adjust how
Java
does parentheses, but I don't recall how.
So the real question is--how big of a problem is this for you? Does
it
cause incorrect results in evaluation anywhere?
-alain
Here is one strange aspect in Java: when I build a classad from string
it does not recognise the value as an integer, as it should be but, instead,
the caught type is -7 which is  "a unary or binary operator" as your
online documentation says:
 
Java Code:
===========
    ClassAdParser cp = new ClassAdParser( "[  one
= -5  ]"  )  ;
    RecordExpr re = ( RecordExpr)   cp.parse()
;
    re.insertAttribute( "two" , (Expr) Constant.getInstance(
-3 )   );
    System.out.println( "OUTPUT: " + re  );
    System.out.println("one:Which is the type?" + re.lookup
("one").type   );
    System.out.println("two: Which is the type?" + re.lookup
("two").type   );
Java Output:
==========
OUTPUT: [ one = (-5); two = -3 ]
one:Which is the type?-7
two: Which is the type?3
 
 
Whilest in C++ the behaviour seems to be the supposed one:
 
 
C++ Code:
=========
ClassAdParser cp ;
ClassAd* classAd ;
classAd = (ClassAd*) cp.ParseExpression(  "[  one = -5 ]"
) ;
Value val ;
val.SetIntegerValue( -6 ) ;
classAd->Insert( "two" ,   (ExprTree*)Literal::MakeLiteral
(val)   );
string       buffer="";
PrettyPrint  unp ;
unp.Unparse(buffer, classAd  ) ;
cout << "OUTPUT = " << buffer << endl << flush
;
classAd->EvaluateExpr ( classAd->Lookup("one")  , val ) ;
cout << "one type: " << val.IsIntegerValue() << endl
<< flush ;
classAd->EvaluateExpr ( classAd->Lookup("two")  , val ) ;
cout << "two type: " <<  val.IsIntegerValue() <<
endl << flush ;
 
C++ Output:
========
OUTPUT =
    [
        two = -6;
        one =  -5
    ]
one type: 1
two type: 1
 
 
 
 
 
 
-- 
   ***
Alessandro Maraschini
GRID R&D Group
Defence, Space & Environment Division
DATAMAT S.p.A.
Via Laurentina, 760 -I- 00143 Rome - Italy
http://www.datamat.it
mailto:alessandro.maraschini@xxxxxxxxxx
Phone: +39 06 5027 4501
Fax: +39 06 5027 2500
 


[← Prev in Thread] Current Thread [Next in Thread→]