FOR-loop in OCL [message #489862] |
Tue, 06 October 2009 09:57 |
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 12:59 |
|
--=-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 "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:
self.parameter->forAll(param|
self.subscriber.operation.parameter->at(self.paramete r->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 12:58 |
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.
|
|
|
Powered by
FUDForum. Page generated in 0.02695 seconds