Home » Modeling » OCL » asOrderedSet() flattening too much?
asOrderedSet() flattening too much? [message #1018337] |
Wed, 13 March 2013 16:26 |
Klaas Gadeyne Messages: 165 Registered: July 2009 |
Senior Member |
|
|
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 21:58 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
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)
>
|
|
| |
Goto Forum:
Current Time: Fri Apr 26 18:38:28 GMT 2024
Powered by FUDForum. Page generated in 0.02604 seconds
|