Menu

Generator functions

2010-04-28
2012-10-08
  • Vladimir Nesterovsky

    I would like to continue with a question about generator functions:
    http://article.gmane.org/gmane.text.xml.xsl.general.mulberrytech/80053

    Previously I've had a negative experience with this kind of functions:

      <xsl:function name="t:generate" as="xs:integer*">
        <xsl:param name="value" as="xs:integer"/>
    
        <xsl:sequence select="$value"/>
        <xsl:sequence select="t:generate($value * 2)"/>
      </xsl:function>
    

    but now, looking into the source, I've found that a little fix helps:

      <xsl:function name="t:generate" as="xs:integer*">
        <xsl:param name="value" as="xs:integer"/>
    
        <xsl:sequence select="$value + 0"/>
        <xsl:sequence select="t:generate($value * 2)"/>
      </xsl:function>
    

    This is related to decided evaluation mode:
    SHARED_APPEND_EXPRESSION or MAKE_CLOSURE.

    You might want to address this case.

     
  • Michael Kay

    Michael Kay - 2010-04-28

    Looks like a case of two optimizations fighting for supremacy. It's difficult
    to make general improvements when this kind of thing happens: optimizations
    that help one program can often have adverse effects on another.

     
  • Vladimir Nesterovsky

    I think that there is some inherent problem in taking decision to spool the
    output
    looking only at expression. In some cases like with sorting and grouping it's
    enough
    but in other cases an expression's consumer would better to decide whether
    it wants to spool its input before the use.