Home » Modeling » Epsilon » Recursive operation - use of Sequence.add()
Recursive operation - use of Sequence.add() [message #489990] |
Tue, 06 October 2009 18:41 |
Eclipse User |
|
|
|
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
|
|
|
Re: Recursive operation - use of Sequence.add() [message #489991 is a reply to message #489990] |
Tue, 06 October 2009 18:49 |
Dimitrios Kolovos Messages: 1776 Registered: July 2009 |
Senior Member |
|
|
Hi Chris,
This happens because the add() method is void, so
return result.add(sig);
adds sig to result and then returns the returned value of add() which is
null.
Cheers,
Dimitris
Chris Holmes wrote:
> 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
--
Spread the word: http://www.eclipse.org/gmt/epsilon/spreadtheword
Follow Epsilon on Twitter: http://twitter.com/epsilonews
|
|
|
Re: Recursive operation - use of Sequence.add() [message #490072 is a reply to message #489991] |
Wed, 07 October 2009 07:55 |
Eclipse User |
|
|
|
Originally posted by: c.k.holmes.lboro.ac.uk
Hi Dimitris,
OK, thanks ... I should have used 'including' doh!:
operation BusAttributes navigateToRoot() : Sequence(Signal) {
var next : BusAttributes;
var sig : Signal := self.ownedBy;
if(self.isRoot()) {
return Sequence{sig};
} else {
next := self.getWhole().getBusAttributes();
return next.navigateToRoot().including(sig);
}
}
Best Wishes
Chris
Dimitris Kolovos wrote:
> Hi Chris,
>
> This happens because the add() method is void, so
>
> return result.add(sig);
>
> adds sig to result and then returns the returned value of add() which is
> null.
>
> Cheers,
> Dimitris
>
> Chris Holmes wrote:
>> 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
>
>
|
|
|
Re: Recursive operation - use of Sequence.add() [message #581478 is a reply to message #489990] |
Tue, 06 October 2009 18:49 |
Dimitrios Kolovos Messages: 1776 Registered: July 2009 |
Senior Member |
|
|
Hi Chris,
This happens because the add() method is void, so
return result.add(sig);
adds sig to result and then returns the returned value of add() which is
null.
Cheers,
Dimitris
Chris Holmes wrote:
> 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
--
Spread the word: http://www.eclipse.org/gmt/epsilon/spreadtheword
Follow Epsilon on Twitter: http://twitter.com/epsilonews
|
|
|
Re: Recursive operation - use of Sequence.add() [message #581520 is a reply to message #489991] |
Wed, 07 October 2009 07:55 |
Eclipse User |
|
|
|
Originally posted by: c.k.holmes.lboro.ac.uk
Hi Dimitris,
OK, thanks ... I should have used 'including' doh!:
operation BusAttributes navigateToRoot() : Sequence(Signal) {
var next : BusAttributes;
var sig : Signal := self.ownedBy;
if(self.isRoot()) {
return Sequence{sig};
} else {
next := self.getWhole().getBusAttributes();
return next.navigateToRoot().including(sig);
}
}
Best Wishes
Chris
Dimitris Kolovos wrote:
> Hi Chris,
>
> This happens because the add() method is void, so
>
> return result.add(sig);
>
> adds sig to result and then returns the returned value of add() which is
> null.
>
> Cheers,
> Dimitris
>
> Chris Holmes wrote:
>> 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
>
>
|
|
|
Goto Forum:
Current Time: Fri Sep 20 12:24:32 GMT 2024
Powered by FUDForum. Page generated in 1.09266 seconds
|