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.
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. Did I actually understand what you said? Thanks On Fri, Apr 2, 2010 at 3:48 PM, Danny Sokolsky <danny.sokol...@marklogic.com > wrote: > No, it is for any parameter. > > > > Function mapping only occurs for singleton parameters, so if you want it > not to happen and it is OK for your function to take the empty sequence, > then type it as a ? (for example, as xs:string?) instead of as a singleton. > Then the empty sequence is a valid parameter to the function and function > mapping will not happen. > > > > -Danny > > > > *From:* general-boun...@developer.marklogic.com [mailto: > general-boun...@developer.marklogic.com] *On Behalf Of *spig > *Sent:* Friday, April 02, 2010 2:30 PM > > *To:* General Mark Logic Developer Discussion > *Subject:* Re: [MarkLogic Dev General] Unexpected behavior > > > > Yeah - I guess I read that line and didn't think much about it until now. > > So, when other parameters in the same call aren't the empty sequence, could > it be considered a bug that the entire function isn't called? > > Steve > > On Fri, Apr 2, 2010 at 3:25 PM, Danny Sokolsky < > danny.sokol...@marklogic.com> wrote: > > What is happening is that, as a result of function mapping, when you pass > in the empty sequence the function is being called 0 times. > > Here is what the documentation says to try and explain this (from the > "MarkLogic Server Enhanced XQuery Language" chapter of the XQuery Reference > Guide): > > One consequence of function mapping, which can be surprising the first time > you see it, is that if the value passed for a parameter is the empty > sequence, it could result in the function being called 0 times (that is, in > the function never runs and results in the empty sequence. For example, if > you entered the empty sequence as the parameter to the above function call, > it returns empty, as follows: > > > xquery version "1.0-ml"; > > declare function local:print-word ($word as xs:string) { $word }; > > local:print-word( () ) > (: > evaluates the print-word function zero times, resulting > in the empty sequence > :) > > The local:print-word function is never called in this case, because it is > iterating over the empty sequence, which causes zero invocations of the > function. If your function calls are fed by code that can return the empty > sequence (an XPath expression, for example), then you might see this > behavior. > > -Danny > > > From: general-boun...@developer.marklogic.com [mailto: > general-boun...@developer.marklogic.com] On Behalf Of spig > > Sent: Friday, April 02, 2010 2:19 PM > > To: General Mark Logic Developer Discussion > > Subject: Re: [MarkLogic Dev General] Unexpected behavior > > > Yes, with xdmp:mapping set to "false" it does throw an expected coercion > error. > > So, how come? > > I was under the impression that xdmp:mapping applies the function's logic > to each parameter. Does xdmp:mapping also not call functions under certain > circumstances? Is there someone who can help explain this functionality or a > document I can read? > > Steve > > So, can someone explain, or point me to a document where xdmp:mapping is > explained? I've read the xdmp:mapping section in the MarkLogic > On Fri, Apr 2, 2010 at 3:05 PM, Micah Dubinko <micah.dubi...@marklogic.com> > wrote: > Try turning off function mapping with this declration at the top (after any > module imports) > > declare option xdmp:mapping "false"; > > Does that at least allow the function to get called (or cause a coercion > error involving ())? > > -m > > On Apr 2, 2010, at 2:01 PM, spig wrote: > > > The point is that the function is never called (it is throwing fn:error > just to prove that it's not called, errors or not). Also, there is no > warning that the function is not being called, or that there is an error in > the parameter. Anyone know why this is? Try running the code and you'll see > what I mean. It's almost like there is a hidden try/catch around my code - > no errors raised and doesn't show that nothing was called. > > > > Steve > > > > On Fri, Apr 2, 2010 at 2:55 PM, Ruth Stryker <ruth.stry...@marklogic.com> > wrote: > > Hi spig, > > > > > > Not sure about fn:error(). Maybe approach with try get instead.? > > > > > > try { > > 1 div 0 > > } > > catch ($e) { > > $e > > } > > > > Or just use an if then else for checking if your field exists.? > > > > > > if(xdmp:get-request-field("q")) > > > > then local:search-results() > > > > else . > > > > > > > > > > From: general-boun...@developer.marklogic.com [mailto: > general-boun...@developer.marklogic.com] On Behalf Of spig > > Sent: Friday, April 02, 2010 1:43 PM > > To: general@developer.marklogic.com > > Subject: [MarkLogic Dev General] Unexpected behavior > > > > > > If I run the following code, my function is never called and no errors > are raised. Any ideas? > > > > > > xquery version "1.0-ml"; > > > > declare function local:test($param1 as xs:string, $param2 as xs:string, > $param3 as xs:string) { > > fn:error() > > }; > > > > let $var := xdmp:get-request-field("non-existent-param") > > > > let $blah := local:test("", "", $var) > > > > return "Function Call Successful" > > > > > > > > Thanks, > > Steve Spigarelli > > > > > > _______________________________________________ > > 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 > > _______________________________________________ > 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 > > > > _______________________________________________ > 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