passing complex parameters to modules

Sunday, 13 August 2023 · 3 messages
GS
Graydon Saunders13 Aug 2023 06:15 #
Hello -- I've got a module full of functions. I've got two (and expect more) queries which import the function module. The queries have slightly different requirements; for example, in one case, it's necessary to use normalize-unicode() during a data regularization step, and in the other case it isn't. These differences are generally not at the top level of function that the query itself calls; they're usually a couple levels down in the function module. It doesn't look like the function module can have its own external variables; if it can, that'd be ideal. Otherwise, it seems like the thing to do is to have each query load a parameter map, but then I have to include that map as a parameter in all the functions calls in the function module, which feels inelegant. And I definitely don't want to start introducing a haze of individual values. Is there a better way to do this? It seems like I'm missing something. Thanks! Graydon
-- Graydon Saunders | graydonish at fastmail.com Þæs oferéode, ðisses swá mæg. -- Deor ("That passed, so may this.")
MH
Martin Honnen13 Aug 2023 12:12 #
Quoted text · Graydon Saunders · 14 lines
On 13.08.2023 04:15, Graydon Saunders wrote: > Hello -- > > I've got a module full of functions. I've got two (and expect more) > queries which import the function module. The queries have slightly > different requirements; for example, in one case, it's necessary to > use normalize-unicode() during a data regularization step, and in the > other case it isn't. These differences are generally not at the top > level of function that the query itself calls; they're usually a > couple levels down in the function module. > > It doesn't look like the function module can have its own external > variables; if it can, that'd be ideal. >
A libary module can certainly have external variables: PS C:\Users\marti\OneDrive\Documents\XQuery\module-var-test> type .\module1.xqm module namespace module1 = "http://example.com/module1";
declare variable $module1:var1 as xs:string external;

declare function module1:foo() {
   $module1:var1
};
PS C:\Users\marti\OneDrive\Documents\XQuery\module-var-test> type
.\main-module1.xq
import module namespace module1 = "http://example.com/module1" at
"module1.xqm";
module1:foo() PS C:\Users\marti\OneDrive\Documents\XQuery\module-var-test> & 'C:\Program Files (x86)\BaseX\bin\basex.bat' '-b{http://example.com/module1}var1=test' .\main-module1.xq test
G
Graydon13 Aug 2023 15:42 #
Quoted text · Graydon Saunders · 2 lines
On Sun, Aug 13, 2023 at 12:12:43PM +0200, Martin Honnen scripsit: > On 13.08.2023 04:15, Graydon Saunders wrote:
[snip]
Quoted text · Martin Honnen · 4 lines
> > It doesn't look like the function module can have its own external > > variables; if it can, that'd be ideal. > > > A libary module can certainly have external variables:
And so it can. (At least if I go for the minimal example.) Thank you, Martin; hopefully I can figure out why I was getting error messages in the full example. -- Graydon
-- Graydon Saunders | graydonish at fastmail.com Þæs oferéode, ðisses swá mæg. -- Deor ("That passed, so may this.")

⚡Generated with XQuery