An interface that uses property/value pairs is a
good way to provide sets of parameters which have
defaults, but where there may be many possible
parameter options. The user does not want to
remember the sequence of possibly dozens of
arguments, many of which may remain at their
First, set default values for the parameters.
Assume we have four parameters that we wish to
use optionally in the function examplefun.
- 'viscosity', which will have a default value of 1
- 'volume', which will default to 1
- 'pie' - which will have default value
- 'description' - a text field, left empty by default
The first argument to examplefun is one which will always be supplied in this example.
params.Viscosity = 1;
params.Volume = 1;
params.Pie = 3.141592653589793
params.Description = '';
Use examplefun, overriding the defaults for 'pie',
'viscosity' and 'description'. The 'volume' parameter
is left at its default value.
Description: 'Hello world'
Note that capitalization was ignored, and the
property 'viscosity' was truncated to 'vis' as
supplied. Also note that the order the pairs were
supplied was arbitrary.
Warning: parse_pv_pairs does not check for data
type in any value, nor for validity of the value
should there be any constraints. These are features
I'd like to add in the future.