Shouldn't condition and true be a no-op?

Thursday, 5 April 2012 · 4 messages
CG
Christian Grünin reply to Meredith Gregory, 5 Apr 2012, 20:405 Apr 2012 18:52 #
Dear Meredith,
Quoted text · Meredith Gregory · 2 lines
>> for ... let ... where C return ... == for ... let ... where C and ( true ) >> return ...
you may be surprised to hear that "true" is no boolean value, but a valid path expression, yielding all element child nodes with the name "true". Using the function "true()" will give you the expected results. Hope this helps, Christian
MG
Meredith Gregory5 Apr 2012 20:31 #
Dear BaseXer's, The following query
for $xqV1 in collection( 'localex' )//kRecord let $xqV2 := $xqV1/*[1] ,
$xqV7 := $xqV1/*[2] where ( count($xqV1/*) = 2 )  and ( for $xqV3 in
$xqV1/node let $xqV4 := $xqV3/*[1] where ( count($xqV3/*) = 1 )  and ( for
$xqV5 in $xqV3/uid let $xqV6 := $xqV5/*[1] where ( count($xqV5/*) = 1 )
 and ( ( ( $xqV6 = <string>uid.value</string> ) or ( fn:string(
fn:node-name( $xqV6 ) ) = "var" ) ) ) and ( $xqV4 = $xqV5 ) return $xqV5 )
and ( $xqV2 = $xqV3 ) return $xqV3 ) return $xqV1
returns our expected result, while
for $xqV1 in collection( 'localex' )//kRecord let $xqV2 := $xqV1/*[1] ,
$xqV7 := $xqV1/*[2] where ( count($xqV1/*) = 2 )  and ( for $xqV3 in
$xqV1/node let $xqV4 := $xqV3/*[1] where ( count($xqV3/*) = 1 )  and ( for
$xqV5 in $xqV3/uid let $xqV6 := $xqV5/*[1] where ( count($xqV5/*) = 1 )
 and ( ( ( $xqV6 = <string>uid.value</string> ) or ( fn:string(
fn:node-name( $xqV6 ) ) = "var" ) ) ) and ( $xqV4 = $xqV5 ) return $xqV5 )
and ( $xqV2 = $xqV3 ) return $xqV3 ) and ( true ) return $xqV1
which is the same query with an 'and ( true )' added to the outer where-clause returns no results. Should we expect that for ... let ... where C return ... == for ... let ... where C and ( true ) return ... ? Best wishes, --greg
-- L.G. Meredith Managing Partner Biosimilarity LLC 7329 39th Ave SW Seattle, WA 98136 +1 206.650.3740 http://biosimilarity.blogspot.com
MG
Meredith Gregory5 Apr 2012 20:40 #
P.S. Meanwhile, replacing 'true' with '1 = 1' has the expected semantics. That is for ... let ... where C return ... == for ... let ... where C and ( 1 = 1 ) return ... At least in the case below. On Thu, Apr 5, 2012 at 9:31 AM, Meredith Gregory <lgreg.meredith at gmail.com>wrote:
Quoted text · Meredith Gregory · 50 lines
> Dear BaseXer's, > > The following query > > for $xqV1 in collection( 'localex' )//kRecord let $xqV2 := $xqV1/*[1] , > $xqV7 := $xqV1/*[2] where ( count($xqV1/*) = 2 ) and ( for $xqV3 in > $xqV1/node let $xqV4 := $xqV3/*[1] where ( count($xqV3/*) = 1 ) and ( for > $xqV5 in $xqV3/uid let $xqV6 := $xqV5/*[1] where ( count($xqV5/*) = 1 ) > and ( ( ( $xqV6 = <string>uid.value</string> ) or ( fn:string( > fn:node-name( $xqV6 ) ) = "var" ) ) ) and ( $xqV4 = $xqV5 ) return $xqV5 ) > and ( $xqV2 = $xqV3 ) return $xqV3 ) return $xqV1 > > returns our expected result, while > > for $xqV1 in collection( 'localex' )//kRecord let $xqV2 := $xqV1/*[1] , > $xqV7 := $xqV1/*[2] where ( count($xqV1/*) = 2 ) and ( for $xqV3 in > $xqV1/node let $xqV4 := $xqV3/*[1] where ( count($xqV3/*) = 1 ) and ( for > $xqV5 in $xqV3/uid let $xqV6 := $xqV5/*[1] where ( count($xqV5/*) = 1 ) > and ( ( ( $xqV6 = <string>uid.value</string> ) or ( fn:string( > fn:node-name( $xqV6 ) ) = "var" ) ) ) and ( $xqV4 = $xqV5 ) return $xqV5 ) > and ( $xqV2 = $xqV3 ) return $xqV3 ) and ( true ) return $xqV1 > > which is the same query with an 'and ( true )' added to the outer > where-clause > > returns no results. > > Should we expect that > > for ... let ... where C return ... == for ... let ... where C and ( true ) > return ... > > ? > > Best wishes, > > --greg > > -- > L.G. Meredith > Managing Partner > Biosimilarity LLC > 7329 39th Ave SW > Seattle, WA 98136 > > +1 206.650.3740 > > http://biosimilarity.blogspot.com > >
-- L.G. Meredith Managing Partner Biosimilarity LLC 7329 39th Ave SW Seattle, WA 98136 +1 206.650.3740 http://biosimilarity.blogspot.com
MG
Meredith Gregoryin reply to Christian Grün, 5 Apr 2012, 18:525 Apr 2012 22:16 #
Dear Christian, Thanks! It's true(), i didn't know that! Constants as zero-ary functions is certainly consistent with Universal Algebra<http://en.wikipedia.org/wiki/Universal_algebra>. So, i'm sympathetic to this design. Best wises, --greg On Thu, Apr 5, 2012 at 9:52 AM, Christian Grün <christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 14 lines
> Dear Meredith, > > >> for ... let ... where C return ... == for ... let ... where C and ( > true ) > >> return ... > > you may be surprised to hear that "true" is no boolean value, but a > valid path expression, yielding all element child nodes with the name > "true". Using the function "true()" will give you the expected > results. > > Hope this helps, > Christian >
-- L.G. Meredith Managing Partner Biosimilarity LLC 7329 39th Ave SW Seattle, WA 98136 +1 206.650.3740 http://biosimilarity.blogspot.com

⚡Generated with XQuery