[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

How to define module local functions.

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


define module
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: http://xquery.com/mailman/listinfo/talk [mailto:http://xquery.com/mailman/listinfo/talk] On Behalf Of
Michael Eichberg
Sent: 05 October 2004 11:35
To: http://xquery.com/mailman/listinfo/talk
Subject:  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:http://xquery.com/mailman/listinfo/talk>
http://xquery.com/mailman/listinfo/talk

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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.