Hi, Tim: Distinguishing the function output from function errors seems like a good idea (witness stdout and stderr).
One possibility is to create a map at the top of the call stack and pass the map through to called functions. Called functions can append to an error key in the map. The benefit is having strongly typed function returns and recording errors or warnings without the global side effects that Ron sensibly cautions against. The cost is the map creation, but that's minimal if you create one map per request. Hoping that helps, Erik Hennum ________________________________________ From: [email protected] [[email protected]] On Behalf Of Ron Hitchens [[email protected]] Sent: Thursday, September 15, 2011 7:12 AM To: General MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] How to effectively pass variables by reference to an xquery function? XQuery is designed as a functional language. One of the design principles of a functional language is that there should not be side effects. One way of insuring no side effects is to not let variables change their values. You never "set" a variable, you bind a value to it that never changes thereafter. So that means you can't modify a variable through a reference because you can't modify variables. You can in fact mutate variables with xdmp:set. But that's a MarkLogic extension that is not part of XQuery proper. There are uses for xdmp:set, but you should always think twice before using it. Inducing side effects in a side-effect free language is definitely a sharp tool. I would recommend returning an XML fragment with all the values you want your function to produce. On Sep 15, 2011, at 2:45 PM, Tim Meagher wrote: > Hi Folks, > > I am calling a function that returns a value but I also want the function to > set a status as well. I'm wondering what is the best way to pass by > reference? I can return an xml structure that contains the return value and > a status, but I'm also wondering about just using xdmp:set() to set a global > variable in a function. _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
