[xquery-talk] How to define module local functions.

Michael Kay mhk at mhk.me.uk
Tue Oct 5 14:06:25 PDT 2004


The current XQuery specification defines this restriction:
 
 The name of every variable and function declared in a library module must
have a namespace URI that is the same as the target namespace of the module.

 
(See http://www.w3.org/TR/xquery/#id-module-declaration )
 
I'm not convinced that the current spec is the final word on the matter;
there is a lot of debate about modules still going on. But that's the way it
currently stands. 
 
The error message I get from Saxon 8.1 is not the message quoted, it is:
 
  XQuery syntax error on line 45 of file:/c:/temp/testlib.xq in
`...irectSupertypes($class)) };`:
    Function internal:isSerializable() is not defined in the module
namespace
 
If I put the two functions in the main module, I get:
 
  XQuery syntax error on line 43 of file:/c:/temp/test.xq in `...ss)) };
xirc:isSerializable`:
    Duplicate definition of function isSerializable
 
which is because of a known bug:
 
http://sourceforge.net/tracker/index.php?func=detail
<http://sourceforge.net/tracker/index.php?func=detail&aid=1037238&group_id=2
9872&atid=397617> &aid=1037238&group_id=29872&atid=397617
 
There will be a patch release soon to fix this.
 
Michael Kay
http://www.saxonica.com/


  _____  

From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com] On Behalf Of
Michael Eichberg
Sent: 05 October 2004 11:35
To: talk at x-query.com
Subject: [xquery-talk] How to define module local functions.



Hello,

 

I have written a library module which defines some variables and functions
for import by other (main or librarary) modules. However, some of the
methods should NOT be callable from other modules, be it library or main
modules, as those methods represent helper functions. Basically, I want to
do something similar to the example depicted below:

 

module namespace xirc        =
"http://www.st.informatik.tu-darmstadt.de/XIRC(5/5/04)";

 

declare namespace internal   = "XIRC-internal";

 

declare function xirc:isSerializable($class as element()*) as xs:boolean {

      if(some $name in $class/@name satisfies $name =
'java.io.Serializable')

      then

            fn:true()

      else

            internal:isSerializable($class)

};

 

declare function internal:isSerializable($class as element()*) as xs:boolean
{

      if (empty($class))

      then

            false()

      else if (some $name in $class/inherits/interface/@name satisfies $name
= 'java.io.Serializable')

      then

            true()

      else 

            (: we have to search the super types :)

            internal:isSerializable(xirc:directSupertypes($class))

};

 

 

In this example the xirc:isSerializable function is the one that has to be
callable by other modules and the internal:isSerializable function is the
one that should be private to this library module. Unfortunately this
example is not working as expected. My XQuery Processor (in this case Saxon
8.1) always generates an

    Function internal:isSerializable has not been declared

error (declaring the function internal:isSerializable before the other
"xirc:" function does not help either).

 

So, my question is, how can I achieve the desired behaviour, or should the
shown example work and that it does not work is a limitation / bug of Saxon?

 

 

Best regards,

Michael Eichberg

 

_________________________________________

Software Technology Group

Department of Computer Science

Darmstadt University of Technology

Alexanderstrasse 10

64289 Darmstadt

Phone.: +49 6151 16 3608

Fax:     +19 6151 16 5410

E-Mail:  <mailto:eichberg at informatik.tu-darmstadt.de>
eichberg at informatik.tu-darmstadt.de

WWW:  <http://www.st.informatik.tu-darmstadt.de/staff/Eichberg>
http://www.st.informatik.tu-darmstadt.de/staff/Eichberg

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://xquery.com/pipermail/talk/attachments/20041005/3fb65554/attachment-0001.htm


More information about the talk mailing list