Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCL iterate - help a begineer
OCL iterate - help a begineer [message #637753] Mon, 08 November 2010 17:15 Go to next message
James is currently offline JamesFriend
Messages: 7
Registered: November 2010
Junior Member
Hi All,

I've been looking at OCL and examples of the collection operation iterate, however one thing i've not been able to identify is whether it is possible to have an iterate inside of another iterate opertaion ( a bit like nested for loops). If it is can someone please show me an example.

Also in OCL when using if then else, if more than one statement is present what are they separted by? For example if x<0 then x=0 and n=0 else n=x

Regards,
James
Re: OCL iterate - help a begineer [message #637767 is a reply to message #637753] Mon, 08 November 2010 18:38 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi James

All OCL expressions specify evaluation of a value, so you can just nest
arbitrarily. Nested iterate is possible, but iterate is not normally
necessary so if you're nesting iterate, you are probably missing a
simpler solution.

if has a clear endif to terminate.

The only problem is let... in... which does not have a clear terminator
so it is adviseable to parenthesize if you use very complicated let
structures.

Regards

Ed Willink

On 08/11/2010 17:15, James wrote:
> Hi All,
>
> I've been looking at OCL and examples of the collection operation
> iterate, however one thing i've not been able to identify is whether
> it is possible to have an iterate inside of another iterate opertaion
> ( a bit like nested for loops). If it is can someone please show me an
> example.
>
> Also in OCL when using if then else, if more than one statement is
> present what are they separted by? For example if x<0 then x=0 and n=0
> else n=x
>
> Regards,
> James
Re: OCL iterate - help a begineer [message #637786 is a reply to message #637767] Mon, 08 November 2010 20:33 Go to previous messageGo to next message
James is currently offline JamesFriend
Messages: 7
Registered: November 2010
Junior Member
Hi Ed,

Thanks for the help, can you explain to me the let expression, as i've had a look on the net and don't understand it.

Regards,
James
Re: OCL iterate - help a begineer [message #637796 is a reply to message #637786] Mon, 08 November 2010 21:35 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi James

For basic tutorial information I suggest you purchase Jos Warmer's and
Anneke Kleppe's book.

Regards

Ed Willink


On 08/11/2010 20:33, James wrote:
> Hi Ed,
>
> Thanks for the help, can you explain to me the let expression, as i've
> had a look on the net and don't understand it.
>
> Regards,
> James
Re: OCL iterate - help a begineer [message #637814 is a reply to message #637796] Tue, 09 November 2010 00:40 Go to previous messageGo to next message
James is currently offline JamesFriend
Messages: 7
Registered: November 2010
Junior Member
In my OCLinEcore code I'm getting a mismatched input '(' expecting ';' at the start of my iterate (see below), which iterates through a collection of numbers and if one is bigger than the other, switch them. Can spot what is causing it.

invariant loop: Number.allInstances()->iterate(n; a:Integer=5 | if valueOfNumber->at(a) < valueOfNumber->at(a-1) then temp=valueOfNumber->at(a-1), valueOfNumber->at(a-1)=valueOfNumber->at(a), valueOfNumber->at(a)=temp, a-1 else a-1 endif);
Re: OCL iterate - help a begineer [message #637829 is a reply to message #637814] Tue, 09 November 2010 05:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi James

I strongly recommend that you read a book on OCL.

You have a cascade of comma-separated terms that make no sense.

You do not understand that '=' is a comparison.

You have not exploited the sortedBy() iteration.

You have not exploited the 1..size() iteration.

You use allInstances() which should be avoided whenever possible.

Regards

Ed Willink


On 09/11/2010 00:40, James wrote:
> In my OCLinEcore code I'm getting a mismatched input '(' expecting ';'
> at the start of my iterate (see below), which iterates through a
> collection of numbers and if one is bigger than the other, switch them.
> Can spot what is causing it.
>
> invariant loop: Number.allInstances()->iterate(n; a:Integer=5 | if
> valueOfNumber->at(a) < valueOfNumber->at(a-1) then
> temp=valueOfNumber->at(a-1),
> valueOfNumber->at(a-1)=valueOfNumber->at(a), valueOfNumber->at(a)=temp,
> a-1 else a-1 endif);
Re: OCL iterate - help a begineer [message #637834 is a reply to message #637814] Tue, 09 November 2010 05:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi James

I strongly recommend that you read a book on OCL.

You have a cascade of comma-separated terms that make no sense.

You do not understand that '=' is a comparison.

You have not exploited the sortedBy() iteration.

You have not exploited the 1..size() iteration.

You use allInstances() which should be avoided whenever possible.

Regards

Ed Willink


On 09/11/2010 00:40, James wrote:
> In my OCLinEcore code I'm getting a mismatched input '(' expecting ';'
> at the start of my iterate (see below), which iterates through a
> collection of numbers and if one is bigger than the other, switch them.
> Can spot what is causing it.
>
> invariant loop: Number.allInstances()->iterate(n; a:Integer=5 | if
> valueOfNumber->at(a) < valueOfNumber->at(a-1) then
> temp=valueOfNumber->at(a-1),
> valueOfNumber->at(a-1)=valueOfNumber->at(a), valueOfNumber->at(a)=temp,
> a-1 else a-1 endif);
Re: OCL iterate - help a begineer [message #637836 is a reply to message #637814] Tue, 09 November 2010 05:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi James

I strongly recommend that you read a book on OCL.

You have a cascade of comma-separated terms that make no sense.

You do not understand that '=' is a comparison.

You have not exploited the sortedBy() iteration.

You have not exploited the 1..size() iteration.

You use allInstances() which should be avoided whenever possible.

Regards

Ed Willink


On 09/11/2010 00:40, James wrote:
> In my OCLinEcore code I'm getting a mismatched input '(' expecting ';'
> at the start of my iterate (see below), which iterates through a
> collection of numbers and if one is bigger than the other, switch them.
> Can spot what is causing it.
>
> invariant loop: Number.allInstances()->iterate(n; a:Integer=5 | if
> valueOfNumber->at(a) < valueOfNumber->at(a-1) then
> temp=valueOfNumber->at(a-1),
> valueOfNumber->at(a-1)=valueOfNumber->at(a), valueOfNumber->at(a)=temp,
> a-1 else a-1 endif);
Re: OCL iterate - help a begineer [message #637837 is a reply to message #637814] Tue, 09 November 2010 05:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi James

I strongly recommend that you read a book on OCL.

You have a cascade of comma-separated terms that make no sense.

You do not understand that '=' is a comparison.

You have not exploited the sortedBy() iteration.

You have not exploited the 1..size() iteration.

You use allInstances() which should be avoided whenever possible.

Regards

Ed Willink


On 09/11/2010 00:40, James wrote:
> In my OCLinEcore code I'm getting a mismatched input '(' expecting ';'
> at the start of my iterate (see below), which iterates through a
> collection of numbers and if one is bigger than the other, switch them.
> Can spot what is causing it.
>
> invariant loop: Number.allInstances()->iterate(n; a:Integer=5 | if
> valueOfNumber->at(a) < valueOfNumber->at(a-1) then
> temp=valueOfNumber->at(a-1),
> valueOfNumber->at(a-1)=valueOfNumber->at(a), valueOfNumber->at(a)=temp,
> a-1 else a-1 endif);
Re: OCL iterate - help a begineer [message #637838 is a reply to message #637829] Tue, 09 November 2010 06:03 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
On 09/11/2010 05:37, Ed Willink wrote:

> You have not exploited the 1..size() iteration.

Correction: the

Integer{1..aCollection->size()}->"iterator"(i : Integer |
... aCollection->at(i) ...)

idiom.

Regards

Ed Willink
Previous Topic:Design pattern creation through ocl
Next Topic:SemanticException
Goto Forum:
  


Current Time: Thu Apr 18 09:29:17 GMT 2024

Powered by FUDForum. Page generated in 0.04144 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top