Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Recursive operation - use of Sequence.add()
Recursive operation - use of Sequence.add() [message #581465] Tue, 06 October 2009 18:41
Eclipse UserFriend
Originally posted by: c.k.holmes.lboro.ac.uk

Hello All,
I'm not sure if this is a bug or just my own stupidity. I have the
following recursive operation (interspersed with print statements):

operation BusAttributes navigateToRoot() : Sequence(Signal) {
var next : BusAttributes;
var sig : Signal := self.ownedBy;
'-----'.println();
sig.asString().println();
'-----'.println();
if(self.isRoot()) {
('stop on ' + sig.asString()).println();
return Sequence{sig};
} else {
var result : Sequence(Signal) := Sequence{};
next := self.getWhole().getBusAttributes();
('again on ' + next.asString()).println();
'-----'.println();
result := next.navigateToRoot();
('result = ' + result).println();
('sig = ' + sig.asString()).println();
return result.add(sig);
}
}

The operation recursively navigates an object hierarchy from leaf to
root, building up a sequence of the leaves visited that are (should then
be) returned. The following is a sanitised execution trace taken from
the console window:

-----
Signal: <SigA>
-----
again on BusAttributesType2: <BusAttB>
-----
-----
Signal: <SigB>
-----
again on BusAttributesType1: <BusAttC>
-----
-----
Signal: <SigC>
-----
again on BusAttributesType2: <BusAttD>
-----
-----
Signal: <SigD>
-----
again on BusAttributesType1: <BusAttE>
-----
-----
Signal: <SigE>
-----
again on BusAttributesType1: <BusAttF>
-----
-----
Signal: <SigF>
-----
again on BusAttributesType1: <BusAttG>
-----
-----
Signal: <SigG>
-----
stop on Signal: <SigG>
result = Sequence {Signal [name=<SigG>]}
sig = Signal: <SigF>
result =
sig = Signal: <SigE>
Method 'add' not found
(C:\EclipseWorkspaces\InterfaceControlDocument\InterfaceCont rolDocument\Operations\BusAttributes.eol@34:18)

It can be seen that <SigF> has not been added to result, and indeed
result now appears to be null rather than the Sequence expected, hence
the error reported by the system in trying to apply the add operation.

If the code of the operation is modified slightly such that we do this
within the 'else' branch:
var result : Sequence(Signal) := Sequence{};
next := self.getWhole().getBusAttributes();
('again on ' + next.asString()).println();
'-----'.println();
result := next.navigateToRoot();
('result = ' + result).println();
('sig = ' + sig.asString()).println();
result.add(sig);
return result;

i.e. we replace the line:
return result.add(sig);
with:
result.add(sig);
return result;

then the operation runs successfully:
stop on Signal: <SigG>
result = Sequence {Signal [name=<SigG>]}
sig = Signal: <SigF>
result = Sequence {Signal [name=<SigG>], Signal [name=<SigF>]}
sig = Signal: <SigE>
result = Sequence {Signal [name=<SigG>], Signal [name=<SigF>], Signal
[name=<SigE>]}
etc.

Placing brackets around (result.add(sig)) has no effect. Is this a bug,
or am I doing something wrong?

Best Wishes
Chris
Previous Topic:Nested Operations by importing EOL Files - using Java
Next Topic:Recursive operation - use of Sequence.add()
Goto Forum:
  


Current Time: Fri Mar 29 02:36:12 GMT 2024

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

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

Back to the top