In C, if you find yourself writing large switch statements (or rafts of if statements), you should consider using pointers to functions instead.
In C++, if you find yourself writing large switch statements (or rafts of if statements), you should consider using objects and polymorphism instead.
In XQuery, If you find yourself writing large typeswitch statements (or rafts of if statements), you should consider using _______________ instead.
Comment here. -m
this is easy to answer if functions were first class citizens in xquery, so if you are willing to use an extension function then you could dispatch by passing around functions.
gl, Jim Fuller
XSL :)
In XQuery, in this situation one should consider using XSLT 2.0 + FXSL 2.0 instead.
As we know well, the FXSL 2.0 library (Written completely in XSLT 2.0) implements higher order functions in XSLT 2.0 and provides an implementation of core library of functions, similar to Haskell’s Prelude, and the way to use them expressively. It also turns every standard F & O function into a higher-order one.
Don’t wait for any new W3 spec and subsequent implementation, FXSL is here now to use.
Cheers,
Dimitre Novatchev
Jim, Do you prefer what you describe to xsl:apply-templates and xsl:templates/@match ?
Dimitre, there is no standard way to do this within an XQuery.
Hello Rob,
A dispatch table is the most appropriate algorithm for xquery (a language based on functions)… unfortunately though it depends on extension functions available.
I think XQuery 1.1 might be addressing this shortcoming, though I have not had a chance yet to fully digest latest draft … I know XQuery 1.1 requirements lists first class functions as a priority.
I didn’t consider XSLT solutions to problem posed in XQuery.
cheers, Jim
Yes, you cannot complete that sequence at the moment, which sucks big time. We need higher order functions. They are included as a “nice to have” thing in the XQuery 1.1 requirements, but they didn’t make it to the WD yet, apparently. Someone should do something :-)
C?