sum

Dieser Ausdruck berechnet die numerische Summe einer Liste von Zahlenwerten (Typ "Number").

Falls die Liste leer ist, gibt dieser Ausdruck das Ergebnis 0 zurück.

Die Liste der Zahlenwerte wird normalerweise durch einen Ausdruck "fixedlist" (siehe fixedlist) oder "dynamiclist" (siehe dynamiclist) bereitgestellt.

<?xml version="1.0" encoding="UTF-8"?>
<RuleSet name="Example_sum"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation=
"http://www.curamsoftware.com/CreoleRulesSchema.xsd">
  <Class name="Person">

    <Attribute name="netWorth">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <!-- Example of <sum> operating on a <fixedlist> -->
        <!-- A person's net worth is the sum of their
             cash, savings and assets -->
        <sum>
          <fixedlist>
            <listof>
              <javaclass name="Number"/>
            </listof>
            <members>
              <reference attribute="totalCash"/>
              <reference attribute="totalSavings"/>
              <reference attribute="totalAssets"/>
            </members>
          </fixedlist>
        </sum>
      </derivation>
    </Attribute>

    <Attribute name="totalAssets">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <!-- Example of <sum> operating on a <dynamiclist> -->
        <!-- The total value of a person's assets is derived by
             summing the value of each asset -->
        <sum>
          <dynamiclist>
            <list>
              <reference attribute="assets"/>
            </list>
            <listitemexpression>
              <reference attribute="value">
                <current/>
              </reference>
            </listitemexpression>
          </dynamiclist>
        </sum>
      </derivation>
    </Attribute>

    <!-- The assets of that this person owns -->
    <Attribute name="assets">
      <type>
        <javaclass name="List">
          <ruleclass name="Asset"/>
        </javaclass>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <!-- NB this example doesn't show how
         total cash/savings is derived -->
    <Attribute name="totalCash">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>
    <Attribute name="totalSavings">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

  </Class>

  <Class name="Asset">

    <!-- The monetary value of the asset -->
    <Attribute name="value">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

  </Class>

</RuleSet>