Your function was never called. You have been bitten by function mapping.
Passing a () value to any function with function mapping turned on doesn't call
the function at all.
Function mapping is turned on by default. If you want it off put this at the
top of your code.
declare option xdmp:mapping "false";
Hope that helps.
- Keith
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of G. Ken Holman
Sent: Friday, June 17, 2011 12:38 PM
To: General MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Why does xs:boolean(())=()?
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
NOTICE: This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any unauthorized
review, use, disclosure or distribution is prohibited. If you are not the
intended recipient, please contact the sender by reply email and destroy all
copies of the original message.
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general