RE: context across function calls

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

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

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())]

Regards
Michael

> -----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
expression?
> Or does the context "reset" when you enter a function call, so that
the
> 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
the
> current formal semantics).  It would be wonderful to get some idea as
to
> 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