[xquery-talk] a conceptual clarification

Amitabh Ojha amitabhojha at rediffmail.com
Tue Mar 1 07:56:14 PST 2005


The question/ point requiring clarification follows after these two XQuery queries :

Query No. 1
-----------
declare namespace my = "urn:foo";

declare function my:square ($x)
{
let $y := $x * $x
return $y
};

let $a := (1 to 5)
for $n in $a return
my:square ($n)


Query  No. 2
------------

declare namespace my = "urn:foo";

declare function my:square ($x)
{
let $x := $x * $x
return $x
};

let $a := (1 to 5)
for $n in $a return
my:square ($n)


Dear members, 

In XQuery, after one binds a variable say  $z  to something  using a  XQuery let  statement,  one is not allowed  to write another  let  statement  which seeks  to  bind  that  same  variable i.e  $z  to  something else.  I am just  trying to  get  more  clear on this.

Please see Query No. 1.  Here, I have used a variable $y within the user defined function my:square.  As you will see,  the calling code causes multiple calls to be placed on  my:square function,  each time with a new argument, thus resulting in a new value of $y,  each time that  the function is called.  Yes, of  course  for the duration of  any one call on the function my:square, there is no attempt to alter $y. So,  is Query No.1  correct with respect to the rule that I just mentioned in para 1 above.  

Next, please see Query No. 2.  Here, the user defined function  my:square is being called with argument $x.  But within the function,  I have put  the statement let  $x := $x * $x.  So, basically  there is one and  only one let  statement  defining the value of  $x here (although  $x is being implicity passed on to this function as an argument).  My question here is,  whether Query No. 2 is violative of the rule stated in para 1 above.  Would a let statement defining $x not as a function of  $x  itself,  e.g say let $x := 10 would have been ok.

Besides, my understanding is that after a XQuery “for”  statement,  if there follows a XQuery “let” statement  within the scope of  that “for” statement,  then it results in a violation of  rule stated in para 1 above.  Is my understanding correct ?

And the last question.  Has this particular rule (I am referring to para 1 above) remained consistently so or have there been changes to it, as the XQuery specification has evolved. 

Shall be grateful for expert advice on this please. Thanks.

Amitabh Ojha


 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://xquery.com/pipermail/talk/attachments/20050301/4a25896e/attachment.htm


More information about the talk mailing list