Function Operations pattern

A function operation contains a function mapping the input values, if any, to output values, possibly in alternate output sets.

In the example in Table 1, svc_expr is used to sum two input values and send the result.

Table 1. Function operation
Example Description
<mix name="Mix">
  <service name="Expr"  
    provision="expr"/>  

  <request name="Sum"  
    service="Expr"  
    fields="value1 value2">    
    <prop name="expr.src"
      content-type="text/x-erlang"><![CDATA[
  Value3 = get("value1") + get("value2"),
  put("value3", Value3),
  "Ok".  
    ]]></prop>
    <reply name="Ok"    
      fields="value3"/>
  </request>
</mix>
The service does not need a property.
The get/1 function retrieves the value of the input fields:
  • value1
  • value2

The put/2 function populates the output field value3 using the Value3 variable.

The last expression in the expr.src property selects the reply "Ok".
Note: The expressions in expr.src are separated by commas and the last expression is terminated by a period.
Note: Do not manually type the <![CDATA...]]> delimiters. The Editor automatically renders text content as XML CDATA sections.

In the example in Table 2, svc_expr is used to produce new field sets by assigning new values to a field. This example shows that it is necessary to have distinct field bindings on going into the script, and on coming out of it.

Table 2. Function operation with variable binding
Example Description
<mix name="Mix">
  <service name="Expr"  
    provision="expr"/>  

  <consume name="Increment"  
    service="Expr"  
    fields="value">    
    <prop name="expr.src"
      content-type="text/x-erlang"><![CDATA[
  put("value", get("value") + 1),
  "Ok".  
    ]]></prop>
    <reply name="Ok"    
      fields="value"/>
  </consume>
</mix>
The service needs no property.

The get/1 function retrieves the value of the value field. The put/2 function assigns it a new value. Sending a field with the same name is only possible for consume/reply operations.

The expr.src property:
  1. Generates the value of the output field by adding 1 to the value of the input field
  2. The last expression selects the "Ok" reply
Note: Do not manually type the <![CDATA...]]> delimiters. The Editor automatically renders text content as XML CDATA sections.