Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsFOR-loop in OCL
https://www.eclipse.org/forums/index.php/mv/msg/155491/489862/#msg_489862
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:
Is there something or can you give me some hints how to improve the
above constraint?
best regards,
Gilbert]]>2009-10-06T09:57:54-00:00Re: FOR-loop in OCL
https://www.eclipse.org/forums/index.php/mv/msg/155491/489899/#msg_489899
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
<!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 "iterate" 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->size()}->iterate(<BR >
i : Integer; badParams : Set(Parameter) = Set{} |<BR>
let param : self.parameter->at(i) in<BR>
if param.typeReference <> self.subscriber.operation.parameter->at(i).typeRefere nce <BR>
then<BR>
badParams->including(param)<BR>
else<BR>
badParams<BR>
endif)<BR>
<BR>
Of course, this is more concise as a reject expression:<BR>
<BR>
self.parameter->reject(param |<BR>
let i : Integer = self.parameter->indexOf(param) in<BR>
param.typeReference <> self.subscriber.operation.parameter->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:
Is there something or can you give me some hints how to improve the
above constraint?
best regards,
Gilbert
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>
--=-ppqdocwM9Hyhp4uNL1kQ--]]>Christian Damus2009-10-06T12:59:25-00:00Re: FOR-loop in OCL
https://www.eclipse.org/forums/index.php/mv/msg/155491/490135/#msg_490135
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.]]>2009-10-07T12:58:33-00:00