[Pharo-project] Bug or feature? XMLElement>>allElementsDo:
In XML-Parser-Nodes we have: XMLNodeWithElements XMLDocument XMLElement A document is composed of elements that can hold recursively other elements XMLNodeWithElements implements (in protocol enumerating) allElementsDo: aBlock "Descend depth-first visiting each element with aBlock." self hasElements ifTrue: [self elementsDo: [:each | each allElementsDo: aBlock]] Looks perfectly normal to me But then: XMLElement implements (in protocol searching !) allElementsDo: aBlock "See superclass version." aBlock value: self. super allElementsDo: aBlock. which means that anXMLElement allElementsDo: [...] runs first on itself and then on its elements ?!? Seems counter intuitive to me. Should I remove this? nicolas
On Mon, 29 Aug 2011, Nicolas Anquetil wrote:
In XML-Parser-Nodes we have:
XMLNodeWithElements XMLDocument XMLElement
A document is composed of elements that can hold recursively other elements
XMLNodeWithElements implements (in protocol enumerating) allElementsDo: aBlock "Descend depth-first visiting each element with aBlock."
self hasElements ifTrue: [self elementsDo: [:each | each allElementsDo: aBlock]]
Looks perfectly normal to me But then:
XMLElement implements (in protocol searching !) allElementsDo: aBlock "See superclass version."
aBlock value: self.
super allElementsDo: aBlock.
which means that anXMLElement allElementsDo: [...] runs first on itself and then on its elements ?!? Seems counter intuitive to me.
Should I remove this?
IMHO you shouldn't, because it is enumerating the whole tree, which is exactly what I'd expect from this method. But the method should be recategorized. Levente
nicolas
⦠and maybe it should be renamed to #withAllElementsDo: ? On 30.08.2011, at 00:01, Levente Uzonyi wrote:
On Mon, 29 Aug 2011, Nicolas Anquetil wrote:
In XML-Parser-Nodes we have:
XMLNodeWithElements XMLDocument XMLElement
A document is composed of elements that can hold recursively other elements
XMLNodeWithElements implements (in protocol enumerating) allElementsDo: aBlock "Descend depth-first visiting each element with aBlock."
self hasElements ifTrue: [self elementsDo: [:each | each allElementsDo: aBlock]]
Looks perfectly normal to me But then:
XMLElement implements (in protocol searching !) allElementsDo: aBlock "See superclass version."
aBlock value: self.
super allElementsDo: aBlock.
which means that anXMLElement allElementsDo: [...] runs first on itself and then on its elements ?!? Seems counter intuitive to me.
Should I remove this?
IMHO you shouldn't, because it is enumerating the whole tree, which is exactly what I'd expect from this method. But the method should be recategorized.
Levente
nicolas
Indeed, it should be named withAllElementsDo: to be consistent with Smalltalk naming, and then it would exactly what the name says :) Doru On 30 Aug 2011, at 07:51, Max Leske wrote:
⦠and maybe it should be renamed to #withAllElementsDo: ?
On 30.08.2011, at 00:01, Levente Uzonyi wrote:
On Mon, 29 Aug 2011, Nicolas Anquetil wrote:
In XML-Parser-Nodes we have:
XMLNodeWithElements XMLDocument XMLElement
A document is composed of elements that can hold recursively other elements
XMLNodeWithElements implements (in protocol enumerating) allElementsDo: aBlock "Descend depth-first visiting each element with aBlock."
self hasElements ifTrue: [self elementsDo: [:each | each allElementsDo: aBlock]]
Looks perfectly normal to me But then:
XMLElement implements (in protocol searching !) allElementsDo: aBlock "See superclass version."
aBlock value: self.
super allElementsDo: aBlock.
which means that anXMLElement allElementsDo: [...] runs first on itself and then on its elements ?!? Seems counter intuitive to me.
Should I remove this?
IMHO you shouldn't, because it is enumerating the whole tree, which is exactly what I'd expect from this method. But the method should be recategorized.
Levente
nicolas
-- www.tudorgirba.com "Live like you mean it."
On Mon, Aug 29, 2011 at 10:25 PM, Nicolas Anquetil <nicolas.anquetil@inria.fr> wrote:
Should I remove this?
it looks like that if you remove "aBlock value: self", aBlock will never get executed. The question is now "does the name #allElementsDo: makes sense with this behavior?" I don't think so. One way to fix it is to move "aBlock value: self" to XMLNodeWithElements>>allElementsDo: -- Damien Cassou http://damiencassou.seasidehosting.st "Lambdas are relegated to relative obscurity until Java makes them popular by not having them." James Iry
participants (5)
-
Damien Cassou -
Levente Uzonyi -
Max Leske -
Nicolas Anquetil -
Tudor Girba