preprocessor instructions for BaseX XQUERY interpreters ?
Friday, 29 November 2013 · 2 messages
JM
jean-marc Mercier29 Nov 2013 10:09 #
Hello,
I have some questions about BaseX interpreter.
1) Is there a way to send preprocessor instructions to BaseX interpreter ?
I am looking to a way to tell the interpreter to skip code based on external instructions, mainly to distinguish the behavior between debug / release modes.
This is achieved in C++ with the macro set of instructions #define, #if, #endif etc... I was wondering whether there exists such a mechanism in XQUERY.
Note : processor instructions might not be relevant for XQuery, since interpreters are heavily optimized.
2) Could you confirm that BaseX interpreter will not try to interpret "dead" code ?
To emulate processor instructions with XQUERY, I am presently using dynamic local variable declarations as (declare function debug(){true()/false()}), and encapsulating my code with a lot of "if (debug()) then (.1.) else (.2.)". Can you confirm that BaseX interpreter skip looking at (.1.) or (.2.) accordingly to the debug function return value ?
Cheers
Jean-Marc
CG
Christian Grün29 Nov 2013 12:30 #
Hi Jean-Marc,
Quoted text · jean-marc Mercier · 2 lines
> Note : processor instructions might not be relevant for XQuery, since > interpreters are heavily optimized.
Dito.
Quoted text · jean-marc Mercier · 2 lines
> 2) Could you confirm that BaseX interpreter will not try to interpret "dead" > code ?
If you want to see what’s going on under the hood, simply check out the output from the InfoView panel (or the query info with -V on command line). The following query…
declare variable $DEBUG := true();
if($DEBUG) then <A/> else <B/>will e. g. be simplified to <A/>. This means that all constants will indeed be pre-evaluated at compile time.
Hope this helps,
Christian
Written for BaseX 7.7. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery