Re: Automatic conversion

Re: Automatic conversion

From: Steffen Zschaler ^lt;>
Date: Fri 10 Mar 2006 - 13:48:34 GMT
Message-ID: <>
Hi Thomas,

Thomas Baar wrote:
> D H. Akehurst wrote:
>> You can use the invariant
>> context Department inv:   self.person->forAll(salary < 
>> self.maxSalaryDept)
>> In the case where the multiplicity is [0..1].
>> Using the '->' operator on objects that are not collections 
>> automatically wraps
>> the object in a Set.
>> Wraping an undefined value into a set results in an empty set, hence 
>> your expression
>> gives true when there are no managers.
> Dave,
> I'm very puzzled by the automatic conversion to collections, it would 
> mean
> that, for example,  5->forAll(x| ...) would be syntactically correct!
> What would then be the point to have two different operators '.' (dot) 
> and
> '->' (arrow) in OCL? So far, it helped the reader to find out if the 
> source
> expression is of object or collection type.
I don't quite see your problem here. The different operators have been 
introduced specifically to allow for automatic conversion. Without such 
a conversion there would be no need for the operators as the parser 
would always be able to decide whether the source is a collection or not 
and, thus, whether a.forAll is valid OCL. By using '->' you essentially 
state that you intend the source to be used as a collection, whatever it 
really is. Conversely, by using '.' you state that you want to use the 
source as a scalar, whatever it really is. This happens, for example, in 
navigation expressions, where ->collect(...) expressions are 
automatically inserted---even though in the last revision of the 
standard I couldn't find anything about this anymore.

Best regards,


Dipl.-Inf. Steffen Zschaler
Research Assistant

Technische Universitšt Dresden
Department of Computer Science

Phone +49 351 463 38555
Fax   +49 351 463 38459
Received on Fri Mar 10 13:50:56 2006