W3C home > Mailing lists > Public > www-ql@w3.org > July to September 2002

RE: context across function calls

From: Michael Rys <mrys@microsoft.com>
Date: Thu, 15 Aug 2002 11:39:18 -0700
Message-ID: <5C39F806F9939046B4B1AFE652500A3A0282CECF@RED-MSG-10.redmond.corp.microsoft.com>
To: "Damien Fisher" <damien@sodatech.com>, <www-ql@w3.org>

The following is my personal interpretation:

Since functions may be compiled outside of the context where they are
called, currently the function definition below would not pick up the
dynamic context. Instead I would expect such a function to raise a
compilation error about that there is not enough context information

Passing implicit contexts is dangerous and should not be encouraged by
the language since it makes the function partially dynamically scoped
(talk to old APL programmers why dynamic scoped functions are a pain to

Instead rewrite your function to take the position and last as argument:

> define function is-mid(xs:integer $p, xs:integer $l) returns
xs:boolean {
>   $p = ($l / 2)
> }
> document("foo.xml")/book/chapter[is-mid(position(),last())]


> -----Original Message-----
> From: Damien Fisher [mailto:damien@sodatech.com]
> Sent: Wednesday, August 14, 2002 7:48 AM
> To: www-ql@w3.org
> Subject: context across function calls
> I refer to a previous post by Per Bothner to www-xml-query-comments:
> http://lists.w3.org/Archives/Public/www-xml-query-
> comments/2002Apr/0023.html
> I'd love some clarification on this issue.
> To summarize the question, consider the following code fragment (taken
> from the above post):
> define function is-mid() {
>    return position() == last() / 2
> }
> document("foo.xml")/book/chapter[is-mid()]
> When is-mid() is called, and it evaluates position() and last(), do
> these return values with respect to the context in the main
> Or does the context "reset" when you enter a function call, so that
> above would (possibly) return an error?
> A *quick* scan of the use cases found none which define functions that
> access an "external" context.  However, the draft standard is very
> ambiguous on this point.
> This is quite an important issue (in terms of its possible effect on
> current formal semantics).  It would be wonderful to get some idea as
> the current intentions of the working group, even if the issue is not
> yet finalized.
> Thanks,
> Damien Fisher
Received on Thursday, 15 August 2002 14:39:50 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:17:15 UTC