Home » Archived » M2M (model-to-model transformation) » [ATL] - Create Integer set and add a new integer.
[ATL] - Create Integer set and add a new integer. [message #762559] |
Thu, 08 December 2011 09:55  |
Eclipse User |
|
|
|
I'm hoping someone may shed a bit of light for me, I can't seem to get this to work.
I set up the variable as:
helper def: int_set: Set(Integer) = Set{8, 15, 6, 3, 19};
then in a do statement I have tried various strategies of adding a new variable without success.
E.g.1 : thisModule.int_set -> insertAt(0,10);
The error : org.eclipse.m2m.atl.engine.emfvm.VMException: Operation not found: Set {19, 3, 6, 8, 15}.insertAt(java.lang.Integer,java.lang.Integer)
E.g.2 : thisModule.int_set <- thisModule.int_set -> insertAt(0,10);
E.g.3 : thisModule.int_set -> append(10);
Just for reference, the variable seems ok since it prints fine with the following:
('thisModule.int_set: ' + thisModule.int_set.toString()).println();
Regards.
|
|
|
Re: [ATL] - Create Integer set and add a new integer. [message #762586 is a reply to message #762559] |
Thu, 08 December 2011 10:47   |
Eclipse User |
|
|
|
Hi
You haven't grasped the benefit of the declarative approach that ATL
supports. You cannot modify anything, you just create it right first
time. No more opportunities for magic side effect mutation of working
values.
So OCL provides no modification operations for Collections, just
constructors of different collections.
e.g aSet->including(10) creates a new set with additional content.
[Whether a new set is actually created is dependent on the
implementation. Within the context of iteration loops, the new Eclipse
OCL implementation recognises stale collections and reuses them.]
Regards
Ed Willink
On 08/12/2011 09:55, spacetempest wrote:
> I'm hoping someone may shed a bit of light for me, I can't seem to get
> this to work.
>
> I set up the variable as:
> helper def: int_set: Set(Integer) = Set{8, 15, 6, 3, 19};
>
> then in a do statement I have tried various strategies of adding a new
> variable without success.
>
> E.g.1 : thisModule.int_set -> insertAt(0,10);
>
> The error : org.eclipse.m2m.atl.engine.emfvm.VMException: Operation
> not found: Set {19, 3, 6, 8,
> 15}.insertAt(java.lang.Integer,java.lang.Integer)
>
>
> E.g.2 : thisModule.int_set <- thisModule.int_set -> insertAt(0,10);
>
> E.g.3 : thisModule.int_set -> append(10);
>
>
> Just for reference, the variable seems ok since it prints fine with
> the following: ('thisModule.int_set: ' +
> thisModule.int_set.toString()).println();
>
> Regards.
>
|
|
| |
Re: [ATL] - Create Integer set and add a new integer. [message #762647 is a reply to message #762586] |
Thu, 08 December 2011 12:52   |
Eclipse User |
|
|
|
Yes, unfortunately haven't yet grasped the declarative approach yet. I'm trying to transform a hierarchy description from one model to a hierarchy into another. For the life of me I can't figure out how to set up the associations between the different levels. I shall post more about this on a new thread. The reason I wished to have a set was that I could have a rule to implement the lowest of children (using a set to record their ids) and then have a rule that progressively implemented the parents.
If there is a better method to reconstruct a hierarchy, I would of course like to hear it (in the other thread I am about to create), but when the ATL documentation says:
"An example of the insertion of the element 15 at the second place is:
Sequence{12, 13, 12}->insertAt(2,15)
which results in:
Sequence{5, 10, 15, 20}"
which looks like a modification operation to me...
@Sylvain: I tried your suggestion
thisModule.int_set <- thisModule.int_set->append(10);
and get the error:
...VMException: Operation not found: Set {19, 3, 6, 8, 15}.append(java.lang.Integer)
|
|
| |
Re: [ATL] - Create Integer set and add a new integer. [message #762827 is a reply to message #762647] |
Thu, 08 December 2011 17:05   |
Eclipse User |
|
|
|
Hi
OCL does define insertAt on Sequence and OrderedSet, but they are
constructors of new collections not mutators.
Sequence{12, 13, 12}->insertAt(2,15)
absolutely should not result in
Sequence{5, 10, 15, 20}
quite apart from the wrong values, the index is wrong too. OCL is a
specification language so indexes count from 1.
Result should be Sequence{12,15,13,12}
Regards
Ed Willink
On 08/12/2011 12:52, spacetempest wrote:
> Yes, unfortunately haven't yet grasped the declarative approach yet.
> I'm trying to transform a hierarchy description from one model to a
> hierarchy into another. For the life of me I can't figure out how to
> set up the associations between the different levels. I shall post
> more about this on a new thread. The reason I wished to have a set
> was that I could have a rule to implement the lowest of children
> (using a set to record their ids) and then have a rule that
> progressively implemented the parents.
>
> If there is a better method to reconstruct a hierarchy, I would of
> course like to hear it (in the other thread I am about to create), but
> when the ATL documentation says:
>
> "An example of the insertion of the element 15 at the second place is:
> Sequence{12, 13, 12}->insertAt(2,15)
> which results in:
> Sequence{5, 10, 15, 20}"
>
> which looks like a modification operation to me...
>
>
> @Sylvain: I tried your suggestion thisModule.int_set <-
> thisModule.int_set->append(10); and get the error:
> ..VMException: Operation not found: Set {19, 3, 6, 8,
> 15}.append(java.lang.Integer)
>
>
|
|
|
Re: [ATL] - Create Integer set and add a new integer. [message #763404 is a reply to message #762827] |
Fri, 09 December 2011 17:49   |
Eclipse User |
|
|
|
Two replies of mine have disappeared while using these forums.
Thanks for taking the time to reply Ed. The example I mentioned (copied from ATL_VMSpecification 2005) was merely to point out my confusion about you saying modification was not possible, and a function existing in the documentation that suggested the opposite. I did not check the numbers assuming they would be correct, a rather amusing typo from the documentation.
I'm still stuck with the original problem that insertAt/append do not function. Do I need to create a new set additional to int_set (the one I proposed in my first post) in order to do this.
|
|
|
Re: [ATL] - Create Integer set and add a new integer. [message #763454 is a reply to message #763404] |
Fri, 09 December 2011 20:00   |
Eclipse User |
|
|
|
Hi
On 09/12/2011 17:49, spacetempest wrote:
> Two replies of mine have disappeared while using these forums. :(
It's very irritating. I use only the newsgroups.
> Thanks for taking the time to reply Ed. The example I mentioned
> (copied from ATL_VMSpecification 2005) was merely to point out my
> confusion about you saying modification was not possible, and a
> function existing in the documentation that suggested the opposite. I
> did not check the numbers assuming they would be correct, a rather
> amusing typo from the documentation.
>
> I'm still stuck with the original problem that insertAt/append do not
> function. Do I need to create a new set additional to int_set (the
> one I proposed in my first post) in order to do this.
>
The success of ATL arises from its providing useful functionality while
QVT was (and arguably still is) gestating. Unfortunately there are a
number of aspects that are a bit pragmatic. Currently it uses its own
rather vintage and not entirely accurate form of OCL.
In OCL, insertAt is only applicable to Sequence and OrderedSet.
OrderedSet was a more recent addition than Set, Sequence and Bag and
realised by some slightly simplistic cut and paste in the OCL specification.
It may be that ATL's OCL predates a coherent OrderedSet.
But Sequence::insertAt() really should work.
Regards
Ed Willink
|
|
| | |
Goto Forum:
Current Time: Sat Feb 15 00:06:31 GMT 2025
Powered by FUDForum. Page generated in 0.03676 seconds
|