XML, Squeak, and speed

Richard A. O'Keefe ok at atlas.otago.ac.nz
Fri May 11 06:17:24 UTC 2001


Michael Rueger <m.rueger at acm.org> provided this code to add to YAX:

    descendants: nodeName
        | result |
        result _ OrderedCollection new.
        self descendants: nodeName do: [:entity | result add: entity].
        ^result! !

    descendants: nodeName do: aBlock
        "self name = nodeName
            ifTrue: [^aBlock value: each]."
        self entities do: [:each | each value name = nodeName
            ifTrue: [aBlock value: each]
            ifFalse: [each value descendants: nodeName do: aBlock]]! !

There is a problem with that.  Or rather, if you start from a vague
term like "descendants", you'll get differing interpretations.
If you have
    <A><B><B><B><C/></B></B></B></A>
how many B descendants does it have?

By my criterion (and code), it has three.
According to this code, it has one.

If you're talking about Shakespeare's plays, there aren't any interesting
constructs that nest inside themselves, so the version quoted above
contains a valuable optimisation.

If you're talking about HTML, with nested DIV and SPAN, or
documents with a nested <SECT><TITLE/>...<SECT><TITLE/>...</SECT>...</SECT>
structure, then the valuable optimisation looks like a bug.

And THIS is what makes using Smalltalk so great.  If the version Mr X
provides doesn't do what you want, Mr Y can whip up his own version in
minutes, possibly using Mr X's as a model.

Don't you just love Smalltalk?





More information about the Squeak-dev mailing list