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 |
Charles anon Messages: 13 Registered: December 2011 |
Junior Member |
|
|
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 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
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 |
Charles anon Messages: 13 Registered: December 2011 |
Junior Member |
|
|
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 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
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)
>
>
|
|
| | | | |
Goto Forum:
Current Time: Thu Sep 26 05:10:30 GMT 2024
Powered by FUDForum. Page generated in 0.06184 seconds
|