Problem with basex:eval
Monday, 27 September 2010 · 4 messages · last reply 30 Sep 2010
MG
Maximilian Gärber27 Sep 2010 08:57 #
Hi there,
I am using basex 6.2.7 (gui version) from the maven repo.
Using eval (see below) gives me: Fehler: [XPST0017] Unknown function "local:name1(...)".
If I call local:name1() directly, it works. Running the same script with Saxon (using saxon:evaluate) works, too.
declare function local:name1() {
let $msg := "hello from name1"
return <msg>{$msg}</msg>
};
declare function local:dispatch($e as element()) {
let $func := local-name($e)
let $res := basex:eval(concat("local:", $func, "()"))
return $res
};
let $elem := <name1>bla</name1>
(: return local:name1() :)
return local:dispatch($elem)Regards,
Max
CG
Christian Grün28 Sep 2010 19:40 #
Dear Max,
in BaseX, the eval() function ignores the existing context. This decision was taken to simplify numerous optimizations. As an example, in the following query, local:n() will be inlined as removed by the dead code detector:
declare function local:n() { 1 };
local:n()Some code optimizations could be suppressed if eval() functions are encountered in the query. This is subject to further work, though.
Sorry; hope this helps anyway,
Christian
Quoted text · Maximilian Gärber · 34 lines
On Mon, Sep 27, 2010 at 8:57 AM, Maximilian Gärber <mgaerber at arcor.de> wrote: > Hi there, > > I am using basex 6.2.7 (gui version) from the maven repo. > > Using eval (see below) gives me: Fehler: [XPST0017] Unknown function > "local:name1(...)". > > If I call local:name1() directly, it works. Running the same script > with Saxon (using saxon:evaluate) works, too. > > declare function local:name1() { > let $msg := "hello from name1" > return <msg>{$msg}</msg> > }; > > declare function local:dispatch($e as element()) { > let $func := local-name($e) > let $res := basex:eval(concat("local:", $func, "()")) > return $res > }; > > let $elem := <name1>bla</name1> > (: return local:name1() :) > return local:dispatch($elem) > > Regards, > > Max > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
MG
Maximilian Gärber29 Sep 2010 11:20 #
Hi Christian,
thanks for clarifying this. To be sure I got this right: The xquery passed to basex:eval() has to be self-contained, no way to refer to anything that's not literally passed to the function?
Regards,
Maxi
2010/9/28 Christian Grün <christian.gruen at gmail.com>:
Quoted text · Christian Grün · 53 lines
> Dear Max, > > in BaseX, the eval() function ignores the existing context. This > decision was taken to simplify numerous optimizations. As an example, > in the following query, local:n() will be inlined as removed by the > dead code detector: > > declare function local:n() { 1 }; > local:n() > > Some code optimizations could be suppressed if eval() functions are > encountered in the query. This is subject to further work, though. > > Sorry; hope this helps anyway, > Christian > > > > On Mon, Sep 27, 2010 at 8:57 AM, Maximilian Gärber <mgaerber at arcor.de> wrote: >> Hi there, >> >> I am using basex 6.2.7 (gui version) from the maven repo. >> >> Using eval (see below) gives me: Fehler: [XPST0017] Unknown function >> "local:name1(...)". >> >> If I call local:name1() directly, it works. Running the same script >> with Saxon (using saxon:evaluate) works, too. >> >> declare function local:name1() { >> let $msg := "hello from name1" >> return <msg>{$msg}</msg> >> }; >> >> declare function local:dispatch($e as element()) { >> let $func := local-name($e) >> let $res := basex:eval(concat("local:", $func, "()")) >> return $res >> }; >> >> let $elem := <name1>bla</name1> >> (: return local:name1() :) >> return local:dispatch($elem) >> >> Regards, >> >> Max >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> >
CG
Christian Grün30 Sep 2010 14:54 #
Quoted text · Maximilian Gärber · 3 lines
> thanks for clarifying this. To be sure I got this right: The xquery > passed to basex:eval() has to be self-contained, no way to refer to > anything that's not literally passed to the function?
…exactly. Feedback on other users is welcome on this one: Who else actually using the eval() function out there? Would you like to have the actual context embedded?
Christian
Written for BaseX 6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery