Using parameters in Dollar Sign Expansion
In the script, we generally use Dollar Sign Expansion to access variable values. However, we can also use them to create macro functions in the script. This is very useful if you need to repeat a function several times.
In this recipe, we are going to extend the mapping function by being able to pass two parameters, and return a different result depending upon which one maps successfully.
Getting ready
Load the following script:
Map1: Mapping Load * Inline [ map_from, map_to A, 1 B, 2 C, 3 ]; Map2: Mapping Load * Inline [ map_from, map_to A, 0.1 B, 0.2 C, 0.3 ]; SET myMacro=Alt(ApplyMap('Map1', $1, Null()), ApplyMap('Map2', $2, Null()), 0); Load * Inline [ Parm1, Parm2 A, A A, B B, A C, A D, A D, B ];
How to do it...
These steps show how to use parameters in a dollar sign expansion:
Add a table box and add
Parm1
andParm2
.Edit the script. Replace the
*
with the following:*, $(myMacro(Parm1, Parm2)) As Res
Reload and add...