Sure. Try this:
declare variable $MYMAP as map:map := map:map();
declare function local:put(
$mymap as map:map,
$key as xs:string,
$val as item()*
) as map:map
{ (map:put($mymap,$key,$val),$mymap)};
let $_ := map:put($MYMAP,"foo",(1,2,3,4,5))
let $mymap := local:put(map:map(),"a","b")
return
for $map at $index in ($mymap,$MYMAP)
for $key in map:keys($map)
return ($key, map:get($map,$key))
________________________________________
From: [email protected]
[[email protected]] On Behalf Of Tim Meagher
[[email protected]]
Sent: Thursday, September 15, 2011 11:15 AM
To: 'General MarkLogic Developer Discussion'
Subject: Re: [MarkLogic Dev General] How to effectively pass
variables by reference to an xquery function?
Hi Colleen,
I haven't used maps before. Do you have any simple examples of mapping to a
global variable or passing a map through a function as a global variable?
Thx,
Tim
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Colleen
Whitney
Sent: Thursday, September 15, 2011 11:37 AM
To: General MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] How to effectively pass variables by
reference to an xquery function?
Yes, it's an extension, but so are try/catch blocks.
You can bind a map to a global variable (in which case it can be referenced
and modified by any function), or create and pass maps through functions as
a local variable just like any other XQuery primitive type, as Erik
suggests.
You can use xdmp:set to modify a global variable, but as Ron noted it does
sidestep the functional paradigm and is a very sharp tool, it's very easy to
shoot yourself in the foot if you've got various functions setting it
concurrently.
--Colleen
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general