Right.  And the other point I was trying to make is that if the function takes 
a zero-or-one parameter, such as "xs:string?", then it is valid to pass in the 
empty sequence and function mapping will not happen on that parameter.  Here is 
an example:

xquery version "1.0-ml";

declare function local:will-map($x as xs:string)
{
 $x, "function will-map was run"
};

declare function local:no-map($x as xs:string?)
{
 $x, "function no-map was run"
};

"function will-map with empty sequence arg:
",
local:will-map(()),
"function no-map with empty sequence arg:
",
local:no-map(())

=>
function will-map with empty sequence arg:

function no-map with empty sequence arg:

function no-map was run

Clear as mud?
-Danny

-----Original Message-----
From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Micah Dubinko
Sent: Friday, April 02, 2010 5:07 PM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] Unexpected behavior

Close. :-)

On Apr 2, 2010, at 4:15 PM, spig wrote:

> So, let me make sure I understand.
> 
> When I declare a function with any number of parameters, if one of those 
> parameters requires a singleton, and I pass in an empty sequence, the 
> function will not likely be called if function mapping is on. This makes 
> sense to me now.

With function mapping enabled, if a function takes a singleton argument, and 
you pass in a sequence, your function will be called n times, where n is the 
length of the sequence. This is true even when n is 0.


> 
> And, by similar logic, it will not throw an error because the function 
> requires a singleton parameter, and I have provided one, albeit the empty 
> sequence. And, since the empty sequence is a valid singleton (is that true) 
> it will not throw an error because the parameters are valid.

Actually, empty sequence is never a valid instance of a singleton type. In 
cases like these the error fails to throw not because the parameter is valid, 
but because the function itself never gets called.

This is easy to get mixed up. I still do at times. -m


_______________________________________________
General mailing list
General@developer.marklogic.com
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
General@developer.marklogic.com
http://xqzone.com/mailman/listinfo/general

Reply via email to