Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » FOR-loop in OCL
FOR-loop in OCL [message #489862] Tue, 06 October 2009 05:57 Go to next message
Eclipse User
Originally posted by: formatzeh.gmx.de

Hello folks,
I'm wondering if it is possible to simulate a for loop in OCL with an
index variable. I have to go through a list and compare the elements
with those of another list. My solution now looks like this:

self.parameter->forAll(param|
self.subscriber.operation.parameter->at(self.parameter->indexOf(param)).typeReference
= param.typeReference
)

Is there something or can you give me some hints how to improve the
above constraint?

best regards,
Gilbert
Re: FOR-loop in OCL [message #489899 is a reply to message #489862] Tue, 06 October 2009 08:59 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 768
Registered: July 2009
Senior Member
--=-ppqdocwM9Hyhp4uNL1kQ
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Gilbert,

The "iterate" expression provides a general-purpose iteration over a
collection, with the ability to accumulate arbitrary results.

For example,

Sequence{1..self.parameter->size()}->iterate(
i : Integer; badParams : Set(Parameter) = Set{} |
let param : self.parameter->at(i) in
if param.typeReference <>
self.subscriber.operation.parameter->at(i).typeReference
then
badParams->including(param)
else
badParams
endif)

Of course, this is more concise as a reject expression:

self.parameter->reject(param |
let i : Integer = self.parameter->indexOf(param) in
param.typeReference <>
self.subscriber.operation.parameter->at(i).typeReference)

but it should give you the general idea.

HTH,

Christian


On Tue, 2009-10-06 at 11:57 +0200, Gilbert Mirenque wrote:

> Hello folks,
> I'm wondering if it is possible to simulate a for loop in OCL with an
> index variable. I have to go through a list and compare the elements
> with those of another list. My solution now looks like this:
>
> self.parameter->forAll(param|
> self.subscriber.operation.parameter->at(self.parameter->indexOf(param)).typeReference
> = param.typeReference
> )
>
> Is there something or can you give me some hints how to improve the
> above constraint?
>
> best regards,
> Gilbert

--=-ppqdocwM9Hyhp4uNL1kQ
Content-Type: text/html; charset="utf-8"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Gilbert,<BR>
<BR>
The &quot;iterate&quot; expression provides a general-purpose iteration over a collection, with the ability to accumulate arbitrary results.<BR>
<BR>
For example,<BR>
<BR>
Sequence{1..self.parameter-&gt;size()}-&gt;iterate(<BR >
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; i : Integer; badParams : Set(Parameter) = Set{} |<BR>
&nbsp;&nbsp;&nbsp; let param : self.parameter-&gt;at(i) in<BR>
&nbsp;&nbsp;&nbsp; if param.typeReference &lt;&gt; self.subscriber.operation.parameter-&gt;at(i).typeRefere nce <BR>
&nbsp;&nbsp;&nbsp; then<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; badParams-&gt;including(param)<BR>
&nbsp;&nbsp;&nbsp; else<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; badParams<BR>
&nbsp;&nbsp;&nbsp; endif)<BR>
<BR>
Of course, this is more concise as a reject expression:<BR>
<BR>
&nbsp;&nbsp; self.parameter-&gt;reject(param |<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; let i : Integer = self.parameter-&gt;indexOf(param) in<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; param.typeReference &lt;&gt; self.subscriber.operation.parameter-&gt;at(i).typeRefere nce) <BR>
<BR>
but it should give you the general idea.<BR>
<BR>
HTH,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Tue, 2009-10-06 at 11:57 +0200, Gilbert Mirenque wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Hello folks,
I'm wondering if it is possible to simulate a for loop in OCL with an
index variable. I have to go through a list and compare the elements
with those of another list. My solution now looks like this:

self.parameter-&gt;forAll(param|
self.subscriber.operation.parameter-&gt;at(self.paramete r-&gt;indexOf(param)).typeReference
= param.typeReference
)

Is there something or can you give me some hints how to improve the
above constraint?

best regards,
Gilbert
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-ppqdocwM9Hyhp4uNL1kQ--
Re: FOR-loop in OCL [message #490135 is a reply to message #489899] Wed, 07 October 2009 08:58 Go to previous message
Eclipse User
Originally posted by: formatzeh.gmx.de

I never got an ocl expression working when it contains LET axpressions.
For example I get the error that the defined variable isn't recognized.
Previous Topic:OCL Parser
Next Topic:oclIsTypeOf and Interfaces
Goto Forum:
  


Current Time: Wed Jul 30 13:22:35 EDT 2014

Powered by FUDForum. Page generated in 0.02962 seconds