[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] [no subject]Dimitre, "everyone on this list knows how to do it and has done this many times (hint: think of markers, or mark-up or XML document/fragment)" Except, of course, Justin, you were saying? There is no need, Dimitre, for you to be condescending in reply and there is no need (for me) to "send this message again under its correct subject" especially given that you agree " your observation *is* correct". My original post was about the semantics of "for-each" vs "map" and, in subsequent discussion, how the concepts of null-ness and nested sequences are emergent from these semantics. I was not seeking a hint or a hack to *emulate* nested sequences in FXSL or anything else, rather, just questioning semantics of the respective idioms. Given that "A proof through examples" suggests that, in your scientific method, examples are valid way of "proving things", me gives the following examples from the Mozilla Javascript code base in which "foreach" and "map" are differentiated as separate functions: /* Array.prototype.forEach Attribution: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:A rray:forEach */ if ( !Array.prototype.forEach) { Array.prototype.forEach = function( f /*, thisp*/) { if ( typeof f !== "function") throw new TypeError(); var thisp = arguments[1]; var len = this.length; for ( var i = 0; i < len; ++i) { if ( i in this) f.call( thisp, this[i], i, this); } }; } /* Array.prototype.map Attribution: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:A rray:map */ if ( !Array.prototype.map) { Array.prototype.map = function( f /*, thisp*/) { if ( typeof f !== "function") throw new TypeError(); var thisp = arguments[1]; var len = this.length; var res = new Array( len); for ( var i = 0; i < len; ++i) { if ( i in this) res[i] = f.call( thisp, this[i], i, this); } return res; }; } I trust this is food for thought and constructive towards future XSLT/XPath incarnations, Justin Johansson --------------------------------------- Justin, Your statement is actually not that f:map() and <xsl:for-each> are different in XSLT, but that the type of some functions cannot be expressed and is flattened in XSLT. For example, we cannot express that the result of mapping a function f() that produces a sequence T* is a sequence of sequences: (T*)* simply, because there isn't anything like sequence of sequences in XPath. So, please, send this message again under its correct subject. While your observation *is* correct, this doesn't mean at all that there is no way to represent a sequence of sequences: everyone on this list knows how to do it and has done this many times (hint: think of markers, or mark-up or XML document/fragment). Whether this is an efficient representation of nested sequences is a totally different topic. -- Cheers, Dimitre Novatchev --------------------------------------- Original thread message: XSLT has been shown to be a member of the "Functional Programming (FP) Family of Languages". see: http://fxsl.sourceforge.net/articles/FuncProg/Functional%20Programming.html
|
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
|