[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Variable number of arguments
>>>>> "Dimitre" == Dimitre Novatchev <dnovatchev@xxxxxxxxx> writes: > On 1/27/06, Michael Kay <mike@xxxxxxxxxxxx> wrote: >> If the arguments are singleton items then I think defining a >> single sequence-valued argument is the best approach (it would >> have been done that way for concat() except for 1.0 >> compatibility). >> >> Another approach which Dimitre has used in FXSL is to define 10 >> different functions taking 1 argument, 2 arguments, etc. >> >> Michael Kay http://www.saxonica.com/ Dimitre> To be more precise, not "10 different functions", but Dimitre> 10 overloads of the same function. No - these are 10 different functions all sharing the same name. Dimitre> Here, the fact that the function name is the same in all Dimitre> 10 cases is really important. Yes, but you have no way in XSLT of specifying this. This is the same as in languages such as C++ and Java - the semantics of functions are not defined. Unlike in Eiffel, where the semantics of a routine are defined by the pre-conditions and post-conditions (together with the class invariant). And re-definition must honour the semantics. (And overloading is not allowed). So all you can do in XSLT (and Java and C++) is to say that different functions sharing the same name have the same semantics BY CONVENTION. Then it is up to you to make sure that your code actually enforces this convention. You have no help from the language in doing this. The alternative approach, of representing a variable number of arguments with one argument - a list typed with the common sub-type of all the permissable arguments, suffers from loss of static typing accuracy. But you do not gain any assurance of semantic consitency with this approach either, so I prefer Dmitre's method, as the way he codes these overloads makes it visually apparent that they all have the same semantics (by immediately calling the "full" version of the function, with extra arguments added). -- Colin Adams Preston Lancashire
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|