Hi,
Yet a cleaner solution would be to make the init function to return
the map to assign to the global variable, so there is no hidden
dependency:
declare variable $global-map := my:init();
declare function my:init() {
let $map := map:map()
...
return
$map
};
If the init code is that simple, the let expression can then even be
used straight in the variable value expression, without using a
function.
Avoiding side-effects when none is required will save you some
(hard-to-track-down) troubles.
Regards,
--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/
On 27 July 2015 at 10:16, Geert Josten wrote:
> Hi Devesh,
>
> XQuery specification allows lazy evaluation, and MarkLogic makes heavy use
> of that. Just don’t put the call to your init function in a declare
> variable, but simply call it before the local:test. Something like:
>
> let $init := local:initialize-variables()
> return
> local:test()
>
> Cheers,
> Geert
>
> From: <[email protected]> on behalf of "Tyagi, Devesh"
> <[email protected]>
> Reply-To: MarkLogic Developer Discussion <[email protected]>
> Date: Monday, July 27, 2015 at 9:55 AM
> To: "[email protected]" <[email protected]>
> Subject: [MarkLogic Dev General] XQuery evaluation
>
> Hi,
>
>
> I have the following piece of code in XQuery:
>
>
> declare variable $triple-predicate-prefix :=
> "http://www.bsi.org/predicates/";
>
> declare variable $triple-predicate-suffix-hasTaxonomyName :=
> "hasTaxonomyName";
>
>
> declare variable $triple-predicates-map := map:map();
>
> declare variable $initialize-variables-caller :=
> local:initialize-variables();
>
>
> declare function local:initialize-variables(){
>
> let $_ :=
> map:put($triple-predicates-map,$triple-predicate-suffix-hasTaxonomyName,fn:concat($triple-predicate-prefix,$triple-predicate-suffix-hasTaxonomyName))
>
> return ()
>
> };
>
>
> declare local:test(){
>
> map:get($triple-predicates-map,$triple-predicate-suffix-hasTaxonomyName)
>
> };
>
>
> local:test()
>
>
> This returns me and empty sequence. The map doesn't get initialized. It
> would be helpful if someone could point me towards the reason and solution
> behind it.
>
>
> Thanks and regards,
>
> Devesh
>
> "This e-mail and any attachments transmitted with it are for the sole use of
> the intended recipient(s) and may contain confidential , proprietary or
> privileged information. If you are not the intended recipient, please
> contact the sender by reply e-mail and destroy all copies of the original
> message. Any unauthorized review, use, disclosure, dissemination,
> forwarding, printing or copying of this e-mail or any action taken in
> reliance on this e-mail is strictly prohibited and may be unlawful."
>
> _______________________________________________
> General mailing list
> [email protected]
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general