logo       

Re: Variable references and prolog grammar: msg#00010

Subject: Re: Variable references and prolog grammar
Michael Kay <mhk@...> writes:

> See section 4.15 of the spec:
> 
> The static context for a function body includes all functions that are
> declared or imported anywhere in the Prolog, but it includes only those
> variables and namespaces that are declared or imported earlier in the Prolog
> than the function that is being defined.
> 
> XQuery differs here from XSLT, which allows forwards references to global
> variables.

Thank you Michael, I was considering the problem by the wrong end, I mean...
4.14 :-)

On the same topic, I was trying to understand why I didn't get an error with :

declare variable $foo := "foo1";
let $foo := "foo2"
return
  $foo

... which returns "foo2".

I was wrongly thinking about a name collision between the 2 variables but the
specs are clear :

>The term variable declaration always refers to a declaration of a variable in a
>Prolog. The binding of a variable to a value in a query expression, such as a
>FLWOR expression, is known as a variable binding, and does not make the
>variable visible to an importing module.

So, we have 2 differents things there, a variable declaration and a variable
binding, even though they are referenced in the same way (that's what makes the
thing powerful ;-)

Now, I was thinking about a another potential name collision :

let $foo := "foo1"
let $foo := "foo2"
return
  $foo

... but it returns "foo2"

Indeed, the specs are clear :

>The for and let clauses of a given FLWOR expression may bind the same variable
>name more than once. In this case, each new binding occludes the previous one,
>which becomes inaccessible in the remainder of the FLWOR expression.

Should we bind the "same" variable in a subsequent part of the FLWOR like in :

let $foo := "foo1"
for $bar in (1 to 1)
  let $foo := "foo2"
  return
    $foo

... it returns "foo2" because the specs have yet another clear answer :

>If a variable reference matches two or more variable bindings that are in
>scope, then the reference is taken as referring to the inner binding, that is,
>the one whose scope is smaller

Now things are very clear :

The order of the declarations in the prolog is significant
It is impossible to have a duplicate variable bindings.

The exact contrary of what I could have thought this morning :-)

Thank you again.

p.b.









<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe