[xquery-talk] a conceptual clarification

Per Bothner per at bothner.com
Tue Mar 1 00:22:34 PST 2005

Amitabh Ojha wrote:
> 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.

No.  You *cannot* write "another  let statement  which seeks to bind
that same  variable", because if you do you're creating a *different*
variable. They just happen to have the same name.

> 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.

Each time you get a *different* variable $y - they just happen to have
the same name.

Consider recursive functions - that should make it clear you can have
many variables with different values but the same name.
Study the local:depth example in 4.15 in the 2005/02 draft.

 > My
> question here is,  whether Query No. 2 is violative of the rule stated 
> in para 1 above.

There is no difference bewteen query 1 and query 2.

> 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.

People (including myself) how argued for prohibiting Query 2, to better
catch errors - and misunderstandings, such as yours.
	--Per Bothner
per at bothner.com   http://per.bothner.com/

More information about the talk mailing list