Skip to main content



      Home
Home » Modeling » OCL » asOrderedSet() flattening too much?
asOrderedSet() flattening too much? [message #1018337] Wed, 13 March 2013 12:26 Go to next message
Eclipse UserFriend
Hi,

I have the following method [*] in a completeOCL document

context Container
def : crossProduct(toAppend : OrderedSet(Integer), currentSet : OrderedSet(OrderedSet(Integer))) : OrderedSet(OrderedSet(Integer)) =
	toAppend->iterate( c : Integer; paths : OrderedSet(OrderedSet(Integer)) = currentSet | 
		 let origSet : OrderedSet(OrderedSet(Integer)) = currentSet in (paths->collect( s : OrderedSet(Integer) | s->append(c) ))->asOrderedSet()->union(origSet)->asOrderedSet()
	)


However, the parser yields an error on the union operation

Unresolved Operation 'OrderedSet(Integer)::union(OrderedSet(OrderedSet(Integer)))'


So it looks like the (first) asOrderedSet() operation is flattening the Sequence(OrderedSet(Integer) (ie. the result of the collect() operation) into an OrderedSet(Integer), instead of "just removing" the duplicate elements and returning an OrderedSet(OrderedSet(Integer)).

Is this a bug, or is something wrong with my expression anyway?

TIA

Klaas


[*] Its goal is to create "crossProducts", ie.
crossProduct( {5, 6} , { {1, 2} {3, 4} }) should return { {1 , 2, 5}, {3, 4, 5}, {1, 2, 6}, {3, 4, 6} }.

Also as a side note: in reality, the operation is not meant to be executed on Integers (ie. I don't have the risk of duplicates)
Re: asOrderedSet() flattening too much? [message #1019004 is a reply to message #1018337] Thu, 14 March 2013 17:58 Go to previous messageGo to next message
Eclipse UserFriend
Hi

In my development workspace, I get a strange dangling reference message
on the "s", but when I hover over the -> of paths->collect I can see the
specialization

IteratorExp *OrderedSet(OrderedSet(Integer))::collect(s :
OrderedSet(Integer) | OrderedSet(Integer)) : Sequence(Integer)*

which is correct. collect was specified in the early days of OCL when
there were no nested collections; it flattens. You need collectNested.

Regards

Ed Willink


On 13/03/2013 16:26, Klaas Gadeyne wrote:
> Hi,
>
> I have the following method [*] in a completeOCL document
>
>
> context Container
> def : crossProduct(toAppend : OrderedSet(Integer), currentSet :
> OrderedSet(OrderedSet(Integer))) : OrderedSet(OrderedSet(Integer)) =
> toAppend->iterate( c : Integer; paths :
> OrderedSet(OrderedSet(Integer)) = currentSet | let origSet :
> OrderedSet(OrderedSet(Integer)) = currentSet in (paths->collect( s :
> OrderedSet(Integer) | s->append(c)
> ))->asOrderedSet()->union(origSet)->asOrderedSet()
> )
>
>
> However, the parser yields an error on the union operation
>
>
> Unresolved Operation
> 'OrderedSet(Integer)::union(OrderedSet(OrderedSet(Integer)))'
>
>
> So it looks like the (first) asOrderedSet() operation is flattening
> the Sequence(OrderedSet(Integer) (ie. the result of the collect()
> operation) into an OrderedSet(Integer), instead of "just removing" the
> duplicate elements and returning an OrderedSet(OrderedSet(Integer)).
>
> Is this a bug, or is something wrong with my expression anyway?
>
> TIA
>
> Klaas
>
>
> [*] Its goal is to create "crossProducts", ie.
> crossProduct( {5, 6} , { {1, 2} {3, 4} }) should return { {1 , 2, 5},
> {3, 4, 5}, {1, 2, 6}, {3, 4, 6} }.
>
> Also as a side note: in reality, the operation is not meant to be
> executed on Integers (ie. I don't have the risk of duplicates)
>
Re: asOrderedSet() flattening too much? [message #1019323 is a reply to message #1019004] Fri, 15 March 2013 08:52 Go to previous message
Eclipse UserFriend
Ed Willink wrote on Thu, 14 March 2013 17:58
Hi

In my development workspace, I get a strange dangling reference message
on the "s", but when I hover over the -> of paths->collect I can see the
specialization

IteratorExp *OrderedSet(OrderedSet(Integer))::collect(s :
OrderedSet(Integer) | OrderedSet(Integer)) : Sequence(Integer)*

which is correct. collect was specified in the early days of OCL when
there were no nested collections; it flattens. You need collectNested.


Should have looked more thoroughly at the spec Embarrassed !

thx!

k
Previous Topic:Operation with Set(Real) as arguments is not recognized, Is this a bug?
Next Topic:Checking ocl syntax
Goto Forum:
  


Current Time: Mon Jul 07 12:11:34 EDT 2025

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

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

Back to the top