Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » When to use . and ->
When to use . and -> [message #1848739] Wed, 15 December 2021 16:35 Go to next message
Jan Crkvic is currently offline Jan CrkvicFriend
Messages: 18
Registered: November 2021
Junior Member
Hi all,

I am working with QVTo and I have gone through the documentation, but I cannot really understand why sometimes I need to use -> and other times I need to use . Is there a specific rule for when to use one and when to use the other?

Thank you in advance!

Re: When to use . and -> [message #1848746 is a reply to message #1848739] Wed, 15 December 2021 20:32 Go to previous messageGo to next message
Christopher Gerking is currently offline Christopher GerkingFriend
Messages: 115
Registered: April 2011
Senior Member
Hi Jan

Let's hope that I will get it right. In general, the . operator is used to access properties or invoke operations of a single element, just like you would do in Java. The -> operator is used to invoke a predefined operation (such as collect, select, etc.) on a Collection of multiple elements. These are the general rules, depending on whether the variable on the left is a single element or a Collection. You can read about these rules in section 7.4.10 "Navigation Operators and Navigation Shorthands" of the OCL specification.

However there are also generalizations of these rules. First, you can also use -> operator on a single element. This will implicitly convert that element into a Set, before invoking the specified operation on that Set. Second, you can also use . operator on a Collection. This will implicitly access the specified property (or invoke the specified operation) of each element in the Collection, before collecting the results in a single flattened Collection.

As you can see, it's already quite confusing. It gets even worse if you take into account the use of -> as a collect shorthand. As stated above, OCL uses -> to invoke a predefined collection operation. However in QVTo you can also use -> to invoke an operation of the single elements in the given collection (or access one of their properties). The results will be collected using the xcollect operation. For example, as described in the QVT specification, list->prop is a shorthand for list->xcollect(i | i.prop), leading to a Sequence of all property values.


Kind regards
Christopher

[Updated on: Thu, 16 December 2021 08:18]

Report message to a moderator

Re: When to use . and -> [message #1848756 is a reply to message #1848746] Thu, 16 December 2021 06:05 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The above description is not correct, it that adds to the confusion without helping you understand that there is an underlying logic. I added 7.4.10 and Table 7.3 to OCL 2.4 specifically to enable users to understand that the design was logical although not wise (see Section 3.3.1 of http://www.eclipse.org/modeling/mdt/ocl/docs/publications/JOT2020OCLReflections/OCLReflections.pdf ) "." is the object navigation operator, "->" is the collection navigation operator. Full stop. Unfortunately when you use object navigation on a collection you are using a shortform for implicit collect, and when you use collection navgation on an object you are using implicit oclAsSet().

Regards

Ed Willink
Re: When to use . and -> [message #1848762 is a reply to message #1848756] Thu, 16 December 2021 08:34 Go to previous messageGo to next message
Christopher Gerking is currently offline Christopher GerkingFriend
Messages: 115
Registered: April 2011
Senior Member
Hi

Ed Willink wrote on Thu, 16 December 2021 01:05
The above description is not correct, it that adds to the confusion without helping you understand that there is an underlying logic.
Where do you see the difference between your description and the first two paragraphs of my description, except that your terminology is probably much more precise?

My third paragraph is about QVTo's use of -> as yet another shorthand for xcollect. Again, this is a logical desing decision but nevertheless confusing.


Regards
Christopher
Re: When to use . and -> [message #1848772 is a reply to message #1848762] Thu, 16 December 2021 12:34 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Christopher

Ok, when I read your words again, they are not actually wrong, just confusing. It is much simpler to first define the two clean cases, then the two short forms that rewrite using the clean cases.

OCL 2.4 introduced the oclAsSet() operation in order to avoid the previous inconsistent magic (4 conversions were to Set and one to Bag)

anObject->aFeature is a short form that is 100% equivalent to anObject.oclAsSet()->aFeature

similarly

aCollection.aFeature is 100% equivalent to aCollection->collect(aFeature)

These are not generalizations. They are short forms / pragmatic use of a gap in the syntax.

Your use of "predefined operation" confuses me. I do not recognise any difference short form-wise between an operation that is defined by the OCL standard, the QVTo standard, a user model, a Complete OCL model or a QVTo helper. They are all operations to which the short forms apply.

(The Pivot-based OCL parser performs precisely the above translation so that oclAsSet / collect is present in the AST and executed as such avoiding the need for magical conversions in other places.)

The QVTo usage is a problem that I was not aware of / forgotten. If QVTo is compatible with OCL then QVTo cannot redefine the implicit collect short form as implicit xcollect. If QVTo does redefine, then there should be a very clear incompatibility statement. From a practical point of view, even implicit collect in OCL is bad, an implicit xcollect in QVTo is worse, since the only point of the "x" is to allow some nasty breaks , continues, raises or returns for which I think the usage really should be pretty explicit even if it could perhaps be statically analyzed

Regards

Ed Willink
Previous Topic:Autocomplete window colors in dark theme
Next Topic:how to transform a bidirectional relationship?
Goto Forum:
  


Current Time: Tue Apr 23 08:42:44 GMT 2024

Powered by FUDForum. Page generated in 0.03102 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top