Eclipse Community Forums Forum Search:

Home » Modeling » OCL » how to concatenate each element of first sequence with every other element of the second sequence
how to concatenate each element of first sequence with every other element of the second sequence Thu, 20 September 2012 07:43
 noi poiMessages: 29Registered: June 2012 Junior Member
hey there.

i am using ATL and i have done the following

helper def : sequenceofcomp : Sequence(String)= Sequence {'oven','powertube'};
helper def : sequenceofbehavior : Sequence(String) = Sequence {'open', 'off'};

helper def : first: Sequence(String) = thisModule.sequenceofcomp ->
collect(c|c.concat(thisModule.sequenceofbehavior -> collect(b|b) ) ) -> iterate(s; seq:Sequence(String) =
Sequence{}| seq.append(s));

the output of this is oven[open,off] and powertube[open,off].
What i want is that oven gets concatenated with open and off and powertube gets concatenated with open and off in a sequence

how can i achieve this

Re: how to concatenate each element of first sequence with every other element of the second sequenc [message #917683 is a reply to message #917558] Thu, 20 September 2012 10:18
 Ed WillinkMessages: 5885Registered: July 2009 Senior Member
Hi

Once you express your desire as an algorithm, you should be able to
express it in OCL.

So try re-expressing, avoiding non-algorithmic English such as

"oven gets concatenated with open"

Why 'oven', why 'open' ?

Once you answer these questions as an iteration your problem is solved.

Hint: Sequence{1..x->size()} is a convenient way of constructing a loop
variable over x.

Regards

On 20/09/2012 08:43, noi poi wrote:
> hey there.
> i am using ATL and i have done the following
>
> helper def : sequenceofcomp : Sequence(String)= Sequence
> {'oven','powertube'};
> helper def : sequenceofbehavior : Sequence(String) = Sequence {'open',
> 'off'};
>
> helper def : first: Sequence(String) = thisModule.sequenceofcomp ->
> collect(c|c.concat(thisModule.sequenceofbehavior -> collect(b|b) )
> ) -> iterate(s; seq:Sequence(String) =
> Sequence{}| seq.append(s));
>
> the output of this is oven[open,off] and powertube[open,off]. What i
> want is that oven gets concatenated with open and off and powertube
> gets concatenated with open and off in a sequence
> how can i achieve this
>