Piece Comparison

Pieces can be compared for equality, containment, position relative to each other, and so on. These tests play a very important role in the piece set operators introduced in the following section.

Without regard to unnamed pieces, the comparison of (named) pieces is quite straightforward -- for example, piece x is equal to piece y if the following is true:

BeginTag(x) == BeginTag(y) and EndTag(x) == EndTag(y)

 

Unfortunately, the situation is more complicated when unnamed pieces are involved. (So far we have only seen unnamed pieces being created as a side-effect of the Pat function -- following sections will illustrate that many other functions have a similar effect.) The problem is that two different pieces (according to our definition above) might have equivalent markup, which confuses the difference between the two pieces. This is a side effect of an unnamed tag becoming "invisible" when the piece is converted to markup.

For example, in See Nested Unnamed Pieces , piece B is nested inside piece A. Applying the Markup function to A and B strips away the unnamed pieces to return the string "WebL" (without any markup). Because of our handling of unnamed pieces as invisible entities (the place holders for patterns), piece A and B should be equal to each other from the programmer's point of view, but is not according to our earlier definition.

 

Nested Unnamed Pieces

 

The first intuition is that WebL should merge neigbouring unnamed tags, so that the equality problem goes away. Unfortunately, experience has shown that merging of unnamed tags is a bad idea. Without going into too much detail, merging of unnamed tags complicates the programmer's mental understanding of the current "shape" of the page, as merging might happen at unexpected situations. This often causes problems when a page is subsequently modified. To give a flavor of the problems that might occur, suppose piece A of the figure was created by thread A, and piece B of the figure was created by an independent thread B. Now let's suppose thread A inserts a character `x' directly after the begin tag of A. In the case of separate (i.e. non-merged) unnamed tags, the resulting situation is easy to visualize. However, with merged unnamed tags, thread A will insert the character inside the piece B created by thread B, which might be unexpected by thread B. These type of problems caused us to reject unnamed tag merging.

Instead, to ensure that A and B are equal, WebL introduces the concept of positions. The position of a tag is a numerical rank of the tag in a page. We number tags from 0 onwards in the order of occurrence in the page, all the while ensuring that sequences of unnamed tags have the same number 1 . See Example of Position Numbering shows the position numbering for a more complicated page consisting of named and unnamed tags. Comparisons of pieces is then made according to the positions of the begin and end tags of the pieces. For example, our definition of piece equality of x and y becomes 2 :

pos(BeginTag(x)) == pos(BeginTag(y)) and

pos(EndTag(x)) == pos(EndTag(y))

 

Using the notion of positions, we can thus define equality, containment, etc. as in See Comparing Pieces x and y . In this table we use the notation beg to indicate the position of the begin tag of a piece, and end to indicate the position of the end tag of a piece. Note that the piece comparison operators equal, inside, after, etc. are not defined in the WebL language itself -- the following section will introduce new language operators based on these definitions.

 

Example of Position Numbering

 

 

Comparing Pieces x and y

Relationship between x and y

Definition

x equal y

beg(x) = beg(y) end(x) end(y)

x inside y

beg(y) £ beg(x) end(x) £ end(y)
¬(beg(x) = beg(y) end(x) = end(y))

x contain y

beg(x) £ beg(y) end(y) £ end(x)
¬(beg(x) = beg(y) end(x) = end(y))

x after y

end(y) < beg(x)

x before y

end(x) < beg(y)

x overlap y

beg(x) £ end(y) beg(y) £ end(x)
¬(beg(x) = beg(y) end(x) = end(y))


1. Readers concerned about inefficient renumbering of tag positions after inserting or deleting tags should be aware that behind the scene, WebL uses an efficient encoding that prevents renumbering positions for large parts of the page after a modification is performed.

2. We introduce here a fictitious WebL function called pos that returns the numerical position of a tag value.


Up Previous Next