need for "fn:variable-lookup" a la "fn:function-lookup"
Thursday, 10 September 2026 · 2 messages · last reply 11 Sep 2026
RS
Rob Stapper10 Sep 2026 13:05 #
Hi,
Is it possible to create a 'fn:variable-lookup' function; the same as '
fn:function-lookup' but for variables.
My public functions are made public through public variables, the functions self are all private. This way functions can easily be forwarded to functions in other modules. All my modules represent classes and for supporting generalization-specialization constructs function need to be forwardable. On the other hand I also make use of poly-morfisme and for this I use fn:function-lookup. Helas, both mechanisms don't align well together. A fn:variable-lookup would be handy here. Alternatively, easily (function-independent) forwarding of functions without the use of variables would also do the trick.
What are your thoughts on this one?.
mvgr.
Rob StapperCG
Christian Grün11 Sep 2026 20:52 #
Hi Rob,
Introducing an fn:variable-lookup function would be more challenging than it seems: the spec allows implementations to fully inline and drop global variables at runtime, in which case they are not available anymore. You can use `fn:load-xquery-module` to access functions and variables instead, but it means your code will be compiled twice.
If you don’t mind having redundant code, you could certainly add wrapper functions:
declare variable $x := 123;
declare variable x() { $x };Hope this helps,
Christian
Quoted text · Rob Stapper · 10 lines
Von: Rob Stapper via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> Gesendet: Donnerstag, 10. September 2026 13:05 An: basex-talk at mailman.uni-konstanz.de Betreff: [basex-talk] need for "fn:variable-lookup" a la "fn:function-lookup" Hi, Is it possible to create a 'fn:variable-lookup' function; the same as 'fn:function-lookup' but for variables. My public functions are made public through public variables, the functions self are all private. This way functions can easily be forwarded to functions in other modules. All my modules represent classes and for supporting generalization-specialization constructs function need to be forwardable. On the other hand I also make use of poly-morfisme and for this I use fn:function-lookup. Helas, both mechanisms don't align well together. A fn:variable-lookup would be handy here. Alternatively, easily (function-independent) forwarding of functions without the use of variables would also do the trick. What are your thoughts on this one?. mvgr. Rob Stapper
Written for BaseX 12.4. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery