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
<service name="Expr"  
  provision="expr"/>  

<request name="Sum"  
  service="Expr"  
  fields="value1 value2">    
  
  <prop name="expr.bind.in"    
    Value1="value1"    
    Value2="value2"/>    

  <prop name="expr.bind.out"    
    Value3="value3"/>    

  <prop name="expr.src"
    content-type="text/x-erlang"><![CDATA[
Value3 = Value1 + Value2,
"Ok".  
  ]]></prop>    

  <reply name="Ok"    
    fields="value3"/>
</request>
Note: Do not manually type the <![CDATA...]]> delimiters. The Editor automatically renders text content as XML CDATA sections.
The service does not need a property.
The expr.bind.in property maps the variables:
  • Value1
  • Value2
to the input fields:
  • value1
  • value2
The expr.bind.out property maps the variable:
  • Value3
to the output field:
  • value3
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.

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
<service name="Expr"  
  provision="expr"/>  

<consume name="Increment"  
  service="Expr"  
  fields="value">    
  
  <prop name="expr.bind.in"    
    Value="value"/>    

  <prop name="expr.bind.out"    
    NewValue="value"/>    

  <prop name="expr.src"
    content-type="text/x-erlang"><![CDATA[
NewValue = Value + 1,
"Ok".  
  ]]></prop>    

  <reply name="Ok"    
    fields="value"/>
</consume>
Note: Do not manually type the <![CDATA...]]> delimiters. The Editor automatically renders text content as XML CDATA sections.
The service needs no property.
The expr.bind.in property binds the variable:
  • Value
to the input field:
  • value
The expr.bind.out property binds the variable:
  • NewValue
to the output field:
  • value

In the Erlang functional expression, you cannot change a variable value. That is why we use the term variable binding.

The new value has to be placed in a new variable, NewValue.

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