From: James F. <jam...@ex...> - 2010-07-17 11:31:33
|
wondering if we are a little lax with how default context is accessible to functions the following xquery is fine -------------------------------------------------------------------- declare function local:test($arg){ name($arg) }; let $a := <test><a></a><b/></test> return $a/local:test(.) -------------------------------------------------------------------- and indeed runs properly but what I found interesting was the following xquery -------------------------------------------------------------------- declare function local:test(){ name() }; let $a := <test><a></a><b/></test> return $a/local:test() -------------------------------------------------------------------- this also runs, which maybe a little strange. I can appreciate that both functions ( e.g. local:test() and name() ) when given no argument use default context but can't find in xquery related specs what the rules are for default context for a function with no arguments. should this throw an [XPDY0002] evaluation of an expression relies on some part of the dynamic context that has not been assigned a value: {context item}. or am I missing something ? thx, James Fuller |
From: Dmitriy S. <sha...@gm...> - 2010-07-17 12:20:54
|
On Sat, 2010-07-17 at 13:31 +0200, James Fuller wrote: > I can appreciate that both functions ( e.g. local:test() and name() ) > when given no argument use default context but can't find in xquery > related specs what the rules are for default context for a function > with no arguments. The function don't have context. You right, it should throw error. (BTW, I like the way it work now) > should this throw an [XPDY0002] evaluation of an expression relies on > some part of the dynamic context that has not been assigned a value: > {context item}. -- Cheers, Dmitriy Shabanov |
From: James F. <jam...@ex...> - 2010-07-18 09:35:47
|
courtesy Norm Walsh via twitter paraphrasing: 'During eval of a fn, the context item, pos, size is undefined, except where it is def by some expr inside the fn' section 3.1.5 Function Calls in XQuery spec defines the correct behavior for this. so looks like we need to sort this out, we should probably also create an xquery level unit test for this as well ... something I think we should do whenever we apply a patch/bug/tweak that can be characterized easily as expected result from xquery unit test. J On 17 July 2010 14:21, Dmitriy Shabanov <sha...@gm...> wrote: > On Sat, 2010-07-17 at 13:31 +0200, James Fuller wrote: >> I can appreciate that both functions ( e.g. local:test() and name() ) >> when given no argument use default context but can't find in xquery >> related specs what the rules are for default context for a function >> with no arguments. > > The function don't have context. You right, it should throw error. (BTW, > I like the way it work now) > >> should this throw an [XPDY0002] evaluation of an expression relies on >> some part of the dynamic context that has not been assigned a value: >> {context item}. > > -- > Cheers, > > Dmitriy Shabanov > > |
From: Adam R. <ad...@ex...> - 2010-07-21 10:16:45
|
Yes I agree we should fix this, are you volunteering ;-) On 18 July 2010 10:35, James Fuller <jam...@ex...> wrote: > courtesy Norm Walsh via twitter > > paraphrasing: 'During eval of a fn, the context item, pos, size is > undefined, except where it is def by some expr inside the fn' > > section 3.1.5 Function Calls in XQuery spec defines the correct > behavior for this. > > so looks like we need to sort this out, we should probably also create > an xquery level unit test for this as well ... something I think we > should do whenever we apply a patch/bug/tweak that can be > characterized easily as expected result from xquery unit test. > > J > > > > > On 17 July 2010 14:21, Dmitriy Shabanov <sha...@gm...> wrote: >> On Sat, 2010-07-17 at 13:31 +0200, James Fuller wrote: >>> I can appreciate that both functions ( e.g. local:test() and name() ) >>> when given no argument use default context but can't find in xquery >>> related specs what the rules are for default context for a function >>> with no arguments. >> >> The function don't have context. You right, it should throw error. (BTW, >> I like the way it work now) >> >>> should this throw an [XPDY0002] evaluation of an expression relies on >>> some part of the dynamic context that has not been assigned a value: >>> {context item}. >> >> -- >> Cheers, >> >> Dmitriy Shabanov >> >> > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > Exist-development mailing list > Exi...@li... > https://lists.sourceforge.net/lists/listinfo/exist-development > -- Adam Retter eXist Developer { United Kingdom } ad...@ex... irc://irc.freenode.net/existdb |
From: James F. <jam...@ex...> - 2010-07-21 10:30:31
|
sure, but I think this maybe a far ranging issue, e.g. declare function local:test(){ //* }; local:test() demonstrates that irregardless of arity, functions called do not restriction any xquery context ... this would have some pretty big ramifications for people's existing xquery code/apps that expect the behavior; perhaps we need to introduce an exist option to be able to switch/configure. It also means that its not just a simple check on xquery context, say in the abstract class org.exist.xquery.Function but we have to do some changes to ensure that no xquery context at all is provided. unsure about doing this, any more thoughts ? thx, J On 21 July 2010 12:16, Adam Retter <ad...@ex...> wrote: > Yes I agree we should fix this, are you volunteering ;-) > > On 18 July 2010 10:35, James Fuller <jam...@ex...> wrote: >> courtesy Norm Walsh via twitter >> >> paraphrasing: 'During eval of a fn, the context item, pos, size is >> undefined, except where it is def by some expr inside the fn' >> >> section 3.1.5 Function Calls in XQuery spec defines the correct >> behavior for this. >> >> so looks like we need to sort this out, we should probably also create >> an xquery level unit test for this as well ... something I think we >> should do whenever we apply a patch/bug/tweak that can be >> characterized easily as expected result from xquery unit test. >> >> J >> >> >> >> >> On 17 July 2010 14:21, Dmitriy Shabanov <sha...@gm...> wrote: >>> On Sat, 2010-07-17 at 13:31 +0200, James Fuller wrote: >>>> I can appreciate that both functions ( e.g. local:test() and name() ) >>>> when given no argument use default context but can't find in xquery >>>> related specs what the rules are for default context for a function >>>> with no arguments. >>> >>> The function don't have context. You right, it should throw error. (BTW, >>> I like the way it work now) >>> >>>> should this throw an [XPDY0002] evaluation of an expression relies on >>>> some part of the dynamic context that has not been assigned a value: >>>> {context item}. >>> >>> -- >>> Cheers, >>> >>> Dmitriy Shabanov >>> >>> >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by Sprint >> What will you do first with EVO, the first 4G phone? >> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first >> _______________________________________________ >> Exist-development mailing list >> Exi...@li... >> https://lists.sourceforge.net/lists/listinfo/exist-development >> > > > > -- > Adam Retter > > eXist Developer > { United Kingdom } > ad...@ex... > irc://irc.freenode.net/existdb > |
From: Dmitriy S. <sha...@gm...> - 2010-07-21 10:49:51
Attachments:
smime.p7s
|
On Wed, 2010-07-21 at 12:30 +0200, James Fuller wrote: > demonstrates that irregardless of arity, functions called do not > restriction any xquery context ... this would have some pretty big > ramifications for people's existing xquery code/apps that expect the > behavior; perhaps we need to introduce an exist option to be able to > switch/configure. +1 for an configurable option -- Cheers, Dmitriy Shabanov |
From: Thomas W. <tho...@gm...> - 2010-07-21 11:05:26
|
James, On the top of the configuration setting it will be a good idea to have an option set the value on fly for the current running XQuery. We may have cases where on the same machine we have old and new code and we need to make sure changing the setting in the config to the current behavior will still allow the new code to run properly switching on fly to the new mode. I hope this will help. Thomas ------ Thomas White Mobile:+44 7711 922 966 Skype: thomaswhite gTalk: thomas.0007 Linked-In:http://www.linkedin.com/in/thomaswhite0007 facebook: http://www.facebook.com/thomas.0007 On 21 July 2010 11:30, James Fuller <jam...@ex...> wrote: > sure, > > but I think this maybe a far ranging issue, e.g. > > declare function local:test(){ > //* > }; > > local:test() > > demonstrates that irregardless of arity, functions called do not > restriction any xquery context ... this would have some pretty big > ramifications for people's existing xquery code/apps that expect the > behavior; perhaps we need to introduce an exist option to be able to > switch/configure. > > It also means that its not just a simple check on xquery context, say > in the abstract class org.exist.xquery.Function but we have to do some > changes to ensure that no xquery context at all is provided. > > unsure about doing this, any more thoughts ? > > thx, J > > > On 21 July 2010 12:16, Adam Retter <ad...@ex...> wrote: > > Yes I agree we should fix this, are you volunteering ;-) > > > > On 18 July 2010 10:35, James Fuller <jam...@ex...> wrote: > >> courtesy Norm Walsh via twitter > >> > >> paraphrasing: 'During eval of a fn, the context item, pos, size is > >> undefined, except where it is def by some expr inside the fn' > >> > >> section 3.1.5 Function Calls in XQuery spec defines the correct > >> behavior for this. > >> > >> so looks like we need to sort this out, we should probably also create > >> an xquery level unit test for this as well ... something I think we > >> should do whenever we apply a patch/bug/tweak that can be > >> characterized easily as expected result from xquery unit test. > >> > >> J > >> > >> > >> > >> > >> On 17 July 2010 14:21, Dmitriy Shabanov <sha...@gm...> wrote: > >>> On Sat, 2010-07-17 at 13:31 +0200, James Fuller wrote: > >>>> I can appreciate that both functions ( e.g. local:test() and name() ) > >>>> when given no argument use default context but can't find in xquery > >>>> related specs what the rules are for default context for a function > >>>> with no arguments. > >>> > >>> The function don't have context. You right, it should throw error. > (BTW, > >>> I like the way it work now) > >>> > >>>> should this throw an [XPDY0002] evaluation of an expression relies on > >>>> some part of the dynamic context that has not been assigned a value: > >>>> {context item}. > >>> > >>> -- > >>> Cheers, > >>> > >>> Dmitriy Shabanov > >>> > >>> > >> > >> > ------------------------------------------------------------------------------ > >> This SF.net email is sponsored by Sprint > >> What will you do first with EVO, the first 4G phone? > >> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > >> _______________________________________________ > >> Exist-development mailing list > >> Exi...@li... > >> https://lists.sourceforge.net/lists/listinfo/exist-development > >> > > > > > > > > -- > > Adam Retter > > > > eXist Developer > > { United Kingdom } > > ad...@ex... > > irc://irc.freenode.net/existdb > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > Exist-development mailing list > Exi...@li... > https://lists.sourceforge.net/lists/listinfo/exist-development > |
From: James F. <jam...@ex...> - 2010-07-21 11:23:25
|
noticed a few irregularities in my original posting, for the sake of clarity I will summarise: as expected, this works -------------------------------------------------------------------- declare function local:test($arg){ name($arg) }; let $a := <test><a></a><b/></test> return local:test($a) -------------------------------------------------------------------- then we have -------------------------------------------------------------------- declare function local:test(){ name() }; let $a := <test><a></a><b/></test> return $a/local:test() -------------------------------------------------------------------- which works, and I can see the sense of it, as we are using the xpath to set context, but can't find the 'words' in the specs that allow this. similarly -------------------------------------------------------------------- declare function local:test(){ name(.) }; //*/local:test() -------------------------------------------------------------------- but what is defo not conformant is something like -------------------------------------------------------------------- declare function local:test(){ //* }; local:test() -------------------------------------------------------------------- which just arbitrarily gives function access to db root context. a few thoughts as I am occupied working on other stuff at the moment but will scan the specs soon: * does an unadorned function, e.g. without being in an explicit xpath actually have a default context always supplied ? e.g. is local:test() shorthand for /./local-test() or something of the kind ? * is context passed via xpath e.g. //$arg/local:test() or //*/local:test() ok, seems to invalidate what is said in the XQuery section 3.1.5 * as a lot of existing xquery code (mine included) wil break with this change, as suggested we need both an exist option and a util function to switch behaviors and have default configured as to how things work now. For those who want more conformant behavior or more security on the context that a function is allowed can switch this default configuration thx, J |
From: Dmitriy S. <sha...@gm...> - 2010-07-21 11:37:40
Attachments:
smime.p7s
|
Note: There are functions like fn:string or fn:base-uri that "... In the zero-argument version of the function, $arg defaults to the context item. That is, calling fn:string() is equivalent to calling fn:string(.). ..." The question "why" didn't get answer ... -- Cheers, Dmitriy Shabanov On Wed, 2010-07-21 at 13:23 +0200, James Fuller wrote: > noticed a few irregularities in my original posting, for the sake of > clarity I will summarise: > > as expected, this works > -------------------------------------------------------------------- > > declare function local:test($arg){ > name($arg) > }; > > let $a := <test><a></a><b/></test> > return > local:test($a) > > -------------------------------------------------------------------- > > then we have > > -------------------------------------------------------------------- > > declare function local:test(){ > name() > }; > > let $a := <test><a></a><b/></test> > return > $a/local:test() > > -------------------------------------------------------------------- > > which works, and I can see the sense of it, as we are using the xpath > to set context, but can't find the 'words' in the specs that allow > this. > > similarly > > -------------------------------------------------------------------- > > declare function local:test(){ > name(.) > }; > > //*/local:test() > > -------------------------------------------------------------------- > > but what is defo not conformant is something like > > -------------------------------------------------------------------- > > declare function local:test(){ > //* > }; > > local:test() > > -------------------------------------------------------------------- > > which just arbitrarily gives function access to db root context. > > a few thoughts as I am occupied working on other stuff at the moment > but will scan the specs soon: > > * does an unadorned function, e.g. without being in an explicit xpath > actually have a default context always supplied ? e.g. is local:test() > shorthand for /./local-test() or something of the kind ? > > * is context passed via xpath e.g. //$arg/local:test() or > //*/local:test() ok, seems to invalidate what is said in the XQuery > section 3.1.5 > > * as a lot of existing xquery code (mine included) wil break with this > change, as suggested we need both an exist option and a util function > to switch behaviors and have default configured as to how things work > now. For those who want more conformant behavior or more security on > the context that a function is allowed can switch this default > configuration |
From: James F. <jam...@ex...> - 2010-07-21 12:05:11
|
On 21 July 2010 13:37, Dmitriy Shabanov <sha...@gm...> wrote: > Note: There are functions like fn:string or fn:base-uri that "... In the > zero-argument version of the function, $arg defaults to the context > item. That is, calling fn:string() is equivalent to calling > fn:string(.). ..." > > The question "why" didn't get answer ... yes, we could suggest to xquery WG that user defined functions might have a similar shorthand but there are probs with this route as well. James Fuller |
From: Dmitriy S. <sha...@gm...> - 2010-07-21 12:16:32
Attachments:
smime.p7s
|
On Wed, 2010-07-21 at 14:05 +0200, James Fuller wrote: > On 21 July 2010 13:37, Dmitriy Shabanov <sha...@gm...> wrote: > > Note: There are functions like fn:string or fn:base-uri that "... In the > > zero-argument version of the function, $arg defaults to the context > > item. That is, calling fn:string() is equivalent to calling > > fn:string(.). ..." > > > > The question "why" didn't get answer ... > > yes, we could suggest to xquery WG that user defined functions might > have a similar shorthand > but there are probs with this route as well. This questing at xsl group F2F meeting at Prague got no answer. Guess, same result for xquery group. My two cent to have context item as parameter if no provided, but groups think that it can confuse end-user (same time there are some functions, strange :-) -- Cheers, Dmitriy Shabanov |