[ATL] Missing OCL language constructs [message #659280] |
Fri, 11 March 2011 14:39  |
Eclipse User |
|
|
|
Hi there,
I just noticed that in ATL it is not possible to use the "CollectionRangeCS" construct:
helper def : allDays : Sequence(Integer) = Sequence{1..31};
This is part of the OCL language (at least since 2.0 - I could not find older definition documents):
Ocl Specification from OMG | Because of the usefulness of a Sequence of consecutive Integers, there is a separate literal to create them. The elements
inside the curly brackets can be replaced by an interval specification, which consists of two expressions of type Integer,
Int-expr1 and Int-expr2, separated by '..'. This denotes all the Integers between the values of Int-expr1 and Int-expr2,
including the values of Int-expr1 and Int-expr2 themselves:
Sequence{ 1..(6 + 4) }
Sequence{ 1..10 }
-- are both identical to
Sequence{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
|
Isn't ATL supporting all OCL definitions?
But much more important to me now: How to do something like Sequence{ 1..31 } ?
For static integers it is easy of course (1, 2, 3, ...) but I would like to use integer variables to create a sequence from n to m.
Any hints appreciated.
Regards,
Sebastian
|
|
|
|
Re: [ATL] Missing OCL language constructs [message #660398 is a reply to message #659492] |
Fri, 18 March 2011 06:18  |
Eclipse User |
|
|
|
Thank you Ronan for pointing this out.
After spending too much time looking for a solution like the one you hinted (using iterate, and collection functions), I realized that the only possible solution to this is to use a recursive helper.
Using iterate and the collection functions without recursion is not going to help because all the functions on a collection of size n return 1 or n (or a fixed multiple of n) items - never an arbitrary k.
If someone else should stumble upon a similar problem:
helper def : createSequence(count : Integer, seq : Sequence(Integer)) : Sequence(Integer) =
if count = 0 then seq else thisModule.createSequence(count-1, seq->append(count)) endif;
Regards,
Sebastian
|
|
|
Powered by
FUDForum. Page generated in 0.02821 seconds