At 2011-06-17 17:58 +0000, Will Thompson wrote:
>Can someone explain why passing this function () returns (), instead 
>of an element or throwing an exception?
>
>declare function local:do-stuff(
>     $bool as xs:boolean
>) as element() {
>         if ($bool)
>         then <x/>
>         else <y/>
>};

I would expect passing the function an argument value of () would 
return a runtime error because there is no optionality allowed on the 
datatype of the argument.  An argument of xs:boolean* would allow the 
empty set to be passed as an argument and <y/> would be returned.

>I see that xs:boolean(())=(),

Correct if you are expressing a comparison operator there.  Both 
sides evaluate to false(), but for slightly different reasons ... or 
rather, the same reason but different mechanisms.

The left-hand side is explicitly computing the 
effective-boolean-value of the empty set and the right-hand side 
implicitly (because it is an operand of the operator) expresses the 
effective-boolean-value of an empty set.

The two false() values equate as true().

If you are using "=" in your statement as a notation for "returns", 
then the statement is not correct ... xs:boolean(()) returns false().

>but it seems like this should either eval to false(), or the 
>function should throw an exception since () isn't a boolean (or is it?).

xs:boolean does a cast of the argument.  The first bullet of the 
documentation cites what is returned when the argument is an empty set:

   http://www.w3.org/TR/2007/REC-xpath-functions-20070123/#func-boolean

The implicit cast for the equality operator is defined here:

   http://www.w3.org/TR/2007/REC-xpath-functions-20070123/#func-boolean-equal

I hope this helps.

. . . . . . . . . . . Ken

--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
G. Ken Holman                 mailto:[email protected]
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to