Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » 2 layers of iterate
2 layers of iterate [message #42510] Thu, 01 November 2007 14:22 Go to next message
Eclipse UserFriend
Originally posted by: nickkirtley.gmail.com

Hi,

I have the following code:

Component.allInstances()->iterate(i;sel : Set(Tuple(c1 : Component,c2
:Component,s : Bag(Component))) = Set{} |
if
i.oclAsType(Component).ownedConnector.end->size()=2 and
i.oclAsType(Component).ownedConnector.getAppliedStereotypes( )- >any(name='TypeConnector')->notEmpty()
then
i.oclAsType(Component).ownedConnector->select(j |
j.oclAsType(Connector).getAppliedStereotypes()->any(name='TypeConnector')- >notEmpty())->iterate(j.oclAsType(Component)
|
if
j.oclAsType(Component).ownedConnector->any(c |
c.oclAsType(Connector).getAppliedStereotypes()->any(name='TypeConnector')).end.role.type- >any(c|
c <>
i.oclAsType(Component)).oclAsType(Component).ownedConnector. getAppliedStereotypes()- >any(name='SuperTypeConnector')->isEmpty()
then
sel->including(Tuple{c1 = i.oclAsType(Component) ,c2 =
j.oclAsType(Component),s = Bag {} })
else
sel->including(Tuple{c1 = i.oclAsType(Component) ,c2 =
j.oclAsType(Component),s
=j.oclAsType(Component).ownedConnector.end.role.type.oclAsTy pe(Component)- >select(k
| k.oclAsType(Component) <> j.oclAsType(Component))})
endif
)
else
sel
endif
)





I get the error:
14:9:16:11 ") else sel unexpected token(s)"
when I have two iterates and using tuples.
I've had this problem before but avoided it by solving the problem another
way, but that's not possible now.

Anyone know what the problem is? anyone else been able to use nested
iterates with tuple return value?

regards,
Nick
Re: 2 layers of iterate [message #42630 is a reply to message #42510] Thu, 01 November 2007 15:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Nick,

It is entirely possible that this is a bug in the OCL grammar definition,
possibly in the rule for tuple literals, collection literals, iterators, or
some combination thereof. There is already one bug report on the
if-expression rule, so maybe that is related, too.

If you can raise a bugzilla report and attach a JUnit test case that
reproduces the problem, then we can look into it. Of course, the simpler
the expression, the easier it will be to debug, so it would be very helpful
if you could reduce the problem from the example below. :-)

Cheers,

Christian


Nick Kirtley wrote:

> Hi,
>
> I have the following code:
>
> Component.allInstances()->iterate(i;sel : Set(Tuple(c1 : Component,c2
> :Component,s : Bag(Component))) = Set{} |
> if
> i.oclAsType(Component).ownedConnector.end->size()=2 and
>
i.oclAsType(Component).ownedConnector.getAppliedStereotypes( )- >any(name='TypeConnector')->notEmpty()
> then
> i.oclAsType(Component).ownedConnector->select(j |
>
j.oclAsType(Connector).getAppliedStereotypes()->any(name='TypeConnector')- >notEmpty())->iterate(j.oclAsType(Component)
> |
> if
> j.oclAsType(Component).ownedConnector->any(c |
>
c.oclAsType(Connector).getAppliedStereotypes()->any(name='TypeConnector')).end.role.type- >any(c|
> c <>
>
i.oclAsType(Component)).oclAsType(Component).ownedConnector. getAppliedStereotypes()- >any(name='SuperTypeConnector')->isEmpty()
> then
> sel->including(Tuple{c1 = i.oclAsType(Component) ,c2 =
> j.oclAsType(Component),s = Bag {} })
> else
> sel->including(Tuple{c1 = i.oclAsType(Component) ,c2 =
> j.oclAsType(Component),s
>
=j.oclAsType(Component).ownedConnector.end.role.type.oclAsTy pe(Component)- >select(k
> | k.oclAsType(Component) <> j.oclAsType(Component))})
> endif
> )
> else
> sel
> endif
> )
>
>
>
>
>
> I get the error:
> 14:9:16:11 ") else sel unexpected token(s)"
> when I have two iterates and using tuples.
> I've had this problem before but avoided it by solving the problem another
> way, but that's not possible now.
>
> Anyone know what the problem is? anyone else been able to use nested
> iterates with tuple return value?
>
> regards,
> Nick
Re: 2 layers of iterate [message #47590 is a reply to message #42630] Tue, 08 January 2008 15:37 Go to previous messageGo to next message
Philipp Kutter is currently offline Philipp KutterFriend
Messages: 306
Registered: July 2009
Senior Member
Hi, Nick and Christian.
Has this bug report been filed?

Is the only thing that needs to be done an example project? I'd
volunteer to create one based on Christian's EMF templates.

Best, Philipp

Christian W. Damus wrote:
> Hi, Nick,
>
> It is entirely possible that this is a bug in the OCL grammar definition,
> possibly in the rule for tuple literals, collection literals, iterators, or
> some combination thereof. There is already one bug report on the
> if-expression rule, so maybe that is related, too.
>
> If you can raise a bugzilla report and attach a JUnit test case that
> reproduces the problem, then we can look into it. Of course, the simpler
> the expression, the easier it will be to debug, so it would be very helpful
> if you could reduce the problem from the example below. :-)
>
> Cheers,
>
> Christian
>
>
> Nick Kirtley wrote:
>
>> Hi,
>>
>> I have the following code:
>>
>> Component.allInstances()->iterate(i;sel : Set(Tuple(c1 : Component,c2
>> :Component,s : Bag(Component))) = Set{} |
>> if
>> i.oclAsType(Component).ownedConnector.end->size()=2 and
>>
> i.oclAsType(Component).ownedConnector.getAppliedStereotypes( )- >any(name='TypeConnector')->notEmpty()
>> then
>> i.oclAsType(Component).ownedConnector->select(j |
>>
> j.oclAsType(Connector).getAppliedStereotypes()->any(name='TypeConnector')- >notEmpty())->iterate(j.oclAsType(Component)
>> |
>> if
>> j.oclAsType(Component).ownedConnector->any(c |
>>
> c.oclAsType(Connector).getAppliedStereotypes()->any(name='TypeConnector')).end.role.type- >any(c|
>> c <>
>>
> i.oclAsType(Component)).oclAsType(Component).ownedConnector. getAppliedStereotypes()- >any(name='SuperTypeConnector')->isEmpty()
>> then
>> sel->including(Tuple{c1 = i.oclAsType(Component) ,c2 =
>> j.oclAsType(Component),s = Bag {} })
>> else
>> sel->including(Tuple{c1 = i.oclAsType(Component) ,c2 =
>> j.oclAsType(Component),s
>>
> =j.oclAsType(Component).ownedConnector.end.role.type.oclAsTy pe(Component)- >select(k
>> | k.oclAsType(Component) <> j.oclAsType(Component))})
>> endif
>> )
>> else
>> sel
>> endif
>> )
>>
>>
>>
>>
>>
>> I get the error:
>> 14:9:16:11 ") else sel unexpected token(s)"
>> when I have two iterates and using tuples.
>> I've had this problem before but avoided it by solving the problem another
>> way, but that's not possible now.
>>
>> Anyone know what the problem is? anyone else been able to use nested
>> iterates with tuple return value?
>>
>> regards,
>> Nick
>
Re: 2 layers of iterate [message #47618 is a reply to message #47590] Tue, 08 January 2008 16:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Philipp,

The OCL in-box hasn't yet been fed this particular delight.

cW

Philipp W. Kutter wrote:

> Hi, Nick and Christian.
> Has this bug report been filed?
>
> Is the only thing that needs to be done an example project? I'd
> volunteer to create one based on Christian's EMF templates.
>
> Best, Philipp
>
> Christian W. Damus wrote:
>> Hi, Nick,
>>
>> It is entirely possible that this is a bug in the OCL grammar definition,
>> possibly in the rule for tuple literals, collection literals, iterators,
>> or
>> some combination thereof. There is already one bug report on the
>> if-expression rule, so maybe that is related, too.
>>
>> If you can raise a bugzilla report and attach a JUnit test case that
>> reproduces the problem, then we can look into it. Of course, the simpler
>> the expression, the easier it will be to debug, so it would be very
>> helpful
>> if you could reduce the problem from the example below. :-)
>>
>> Cheers,
>>
>> Christian

-----8<-----
Re: 2 layers of iterate [message #48220 is a reply to message #47618] Tue, 15 January 2008 12:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nickkirtley.gmail.com

Hi,

I didn't add it to bugzilla.
I'll come up with the simplest code in which the problem exists tonight.

Nick
Re: 2 layers of iterate [message #48250 is a reply to message #48220] Tue, 15 January 2008 13:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Thanks, Nick!

That will help a great deal.

Cheers,

Christian


Nick wrote:

> Hi,
>
> I didn't add it to bugzilla.
> I'll come up with the simplest code in which the problem exists tonight.
>
> Nick
Re: 2 layers of iterate [message #48607 is a reply to message #42510] Wed, 16 January 2008 11:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nickkirtley.gmail.com

hi christian,

Could you check this code to see whether this should work?
According to me it should but I might have made a mistake.

Component.allInstances()->iterate(i;pairs : Set(Tuple(c1 : Component, p1 :
Port)) = Set{} |
let comp: Component = i.oclAsType(Component) in
comp.ownedPort->iterate(j.oclAsType(Port) |
let po : Port = j.oclAsType(Port) in
pairs->including(Tuple{c1=comp, p1 = po }) ))

This should iterate through the components, then iterate through ports of
the components and add them to the tuple.
This assumes that components have ports. But I did this to keep the query
as simple as possible.

Error given:

Results:
5:61:5:61 ") unexpected token(s)"

I installed the newest version, 1.2.0M4, and got a different error:
3:41:3:49 missing "| oclExpressionCS )" to complete scope



Although if I count the brackets they add up.




If I do the following it works:
Component.allInstances()->iterate(i;pairs : Set(Tuple(c1 : Component, p1 :
Port)) = Set{} |
pairs->including(Tuple{c1=i.oclAsType(Component), p1 =
i.oclAsType(Component).ownedPort->any(true) }) )

Results:
org.eclipse.ocl.uml.UMLEvaluationEnvironment$TupleImpl@59f4f0c1
org.eclipse.ocl.uml.UMLEvaluationEnvironment$TupleImpl@71f3491f
org.eclipse.ocl.uml.UMLEvaluationEnvironment$TupleImpl@75b03ff0
org.eclipse.ocl.uml.UMLEvaluationEnvironment$TupleImpl@63d1f0a7
org.eclipse.ocl.uml.UMLEvaluationEnvironment$TupleImpl@533622bb




Your thoughts?


regards,

Nick
Re: 2 layers of iterate [message #48711 is a reply to message #48607] Wed, 16 January 2008 14:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Nick,

The problem with your example, below, is the attempt to place an
expression "j.oclAsType(Port)" where a variable declaration is required in
the iterate() expression. Moreover, when only one variable is specified in
an iterate, it is the accumulator, which requires declaration of a type and
initial value expression (the iterator variable being implicit).

This whole expression can be simplified, though, thus:

Component.allInstances()->collect(c |
c.ownedPort->collect(p | Tuple{c1 = c, p1 = p}))->asSet()

which takes advantage of the fact that the "collect" iterator flattens
nested collections.

Note that there is no need for any oclAsType() casting.

Cheers,

Christian


nick wrote:

> Component.allInstances()->iterate(i;pairs : Set(Tuple(c1 : Component, p1 :
> Port)) = Set{} |
> let comp: Component = i.oclAsType(Component) in
> comp.ownedPort->iterate(j.oclAsType(Port) |
> let po : Port = j.oclAsType(Port) in
> pairs->including(Tuple{c1=comp, p1 = po }) ))
Re: 2 layers of iterate [message #48741 is a reply to message #48711] Wed, 16 January 2008 14:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nickkirtley.gmail.com

Hi,

I know that it can be solved much easier but the whole point of this was
to try an iterate within an iterate. Does it work once you correct the
problem?

nick
Re: 2 layers of iterate [message #48770 is a reply to message #48741] Wed, 16 January 2008 16:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Nick,

As I indicated, the problem was in the declaration of iterator/accumulator
variables in the nested iterate expression. Thus, the following parses:

Component.allInstances()->iterate(i; pairs : Set(Tuple(c1 : Component, p1 :
Port)) = Set{} |
let comp : Component = i.oclAsType(Component) in
comp.ownedPort->iterate(j; pairs2 : Set(Tuple(c1 : Component, p1 : Port))
= Set{} |
let po : Port = j.oclAsType(Port) in pairs2->including(Tuple{c1 = comp,
p1 = po}) ))

but does not achieve the goal of collecting all (component, port) pairs. It
only gets the pairs for the last component because the result of the inner
iterate *replaces* the "pairs" value in the outer iterate.

Cheers,

Christian

Nick wrote:

> Hi,
>
> I know that it can be solved much easier but the whole point of this was
> to try an iterate within an iterate. Does it work once you correct the
> problem?
>
> nick
Re: 2 layers of iterate [message #52651 is a reply to message #48770] Tue, 11 March 2008 15:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nickkirtley.gmail.com

hi,

I was looking back at this question of mine.

OCL queries can, in my opinion, be quite complicated. What's the best book
on OCL and in particular (relatively) complicated queries out there?
What do you use Christian?

cheers,
Nick
Re: 2 layers of iterate [message #52678 is a reply to message #52651] Tue, 11 March 2008 15:44 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Nick,

Indeed, OCL queries can become large. I guess that's partly a consequence
of the relatively small and simple syntax. :-)

The classic text on OCL is the Warmer and Kleppe book which, I think, has
been updated for OCL 2.0. A search for the keywords "Warmer" and "OCL" on
Amazon should find it easily.

I can't actually recommend this book, though, because I have never read it.
The only reference that I have is the specification.

HTH,

Christian


nick wrote:

> hi,
>
> I was looking back at this question of mine.
>
> OCL queries can, in my opinion, be quite complicated. What's the best book
> on OCL and in particular (relatively) complicated queries out there?
> What do you use Christian?
>
> cheers,
> Nick
Previous Topic:CollectionItem -> item direct edition
Next Topic:[Announce] MDT OCL 1.2.0 I200803121800 is available
Goto Forum:
  


Current Time: Fri Mar 29 02:34:29 GMT 2024

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

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

Back to the top