RE: [xsl] () equivalent to () ?

Subject: RE: [xsl] () equivalent to () ?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 22 Aug 2005 14:48:42 +0100
> Is the empty sequence equal to itself?

Define "equal". The "=" operator returns false, the "eq" operator returns
(), the deep-equals() function returns true, the "is" operator returns ().
> 
> I would say yes, because what charactarizes the empty 
> sequence, its length and 
> its members(AFAICT), is always the same. IIRC, the empty 
> sequence is a 
> constant value and hence it must by common principles be 
> identical to itself.

Sequences don't have identity; and there's more than one possible definition
of equality.

> As a consequence, the expression "data( () )" should be 
> equivalent to its 
> argument, "()", the empty sequence.

Be careful with words: you've drifted from "equal" to "identical" to
"equivalent".

It's true that the result of data(()) is (). However, systems are allowed to
do static type checking. The static types inferred for () and data(()) are
different. So there's at least one sense in which they are not equivalent.
> 
> However, testing this theory in practice in a host language 
> such as XSLT 2.0 
> is impossible(?) since all comparison operators returns the 
> empty sequence 
> when an operand is the empty sequence.

You're talking about a new comparison operation of your own invention which
you haven't fully defined, and which seems to differ slightly from those
already defined in the language. You're welcome to do this. First you need
to define what you want its semantics to be, and then you can implement it
as a function. But so far, you haven't defined its semantics except by
appeal to "common principles" - which you will quickly find are not as
common as you thought.

Michael Kay
http://www.saxonica.com/

Current Thread