Chapter 10: functions, 10 functions, Hapter – Teledyne LeCroy Merlins Wand - CSL manual (CATC Scripting Language Manual) User Manual
Page 35: Unctions
29
CATC Scripting Language for Bluetooth Analyzers
CATC
Manual Ver. 1.21
C
HAPTER
10: F
UNCTIONS
A function is a named statement or a group of statements that are executed as one
unit. All functions have names. Function names must contain only alphanumeric
characters and the underscore (
_
) character, and they cannot begin with a number.
A function can have zero or more parameters, which are values that are passed to
the function statement(s). Parameters are also known as arguments. Value types are
not specified for the arguments or return values. Named arguments are local to the
function body, and functions can be called recursively.
The syntax for a function declaration is
name(<parameter1>, <parameter2>, ...)
{
<statements>
}
The syntax to call a function is
name(<parameter1>, <parameter2>, ...)
So, for example, a function named
add
can be declared like this:
add(x, y)
{
return x + y;
}
and called this way:
add(5, 6);
This would result in a return value of 11.
Every function returns a value. The return value is usually specified using a
return
statement, but if no
return
statement is specified, the return value will
be the value of the last statement executed.
Arguments are not checked for appropriate value types or number of arguments
when a function is called. If a function is called with fewer arguments than were
defined, the specified arguments are assigned, and the remaining arguments are
assigned to null. If a function is called with more arguments than were defined, the
extra arguments are ignored. For example, if the function
add
is called with just one
argument
add(1);
the parameter
x
will be assigned to 1, and the parameter
y
will be assigned to null,
resulting in a return value of 1. But if
add
is called with more than two arguments
add(1, 2, 3);
x
will be assigned to 1,
y
to 2, and 3 will be ignored, resulting in a return value of 3.