Fundamentals: Macro Function Parameter Types

A Function Parameter is the value and type of value passed into a macro command inside the parenthesis (). For example, the math function Absolute Value whose definition is D=ABS(N) takes a single numeric parameter and returns a decimal value. For example:

#RETVAL=ABS(-1) // #RETVAL contains 1

In this case ABS() takes "-1" as its parameter and returns "1" which is assigned to the decimal variable #RETVAL.

Parameter Types

There are three basic Data Types in the SmartCAM macro language, integer, decimal and string. Macro functions return values as one of these data types.

Function parameters, the items inside the parenthesis, are algebraic or string expressions that yield a result of these same three data types. Expressions can be as simple as a constant, or a variable, or a more complex combination of contestants, variables, operators, macro functions, and built in math functions yielding a numeric or string result.

Basically, any expression that can be placed on the right hand side of an equals assignment (i.e. #MYVAR = right hand side expression), can be used directly as a function parameter.

Examples of integer expressions:

Examples of decimal expressions:

Examples of string expressions:

Numeric Macro Example

DECIMAL:#RETVAL
DECIMAL:#PARAMETER
#PARAMETER=-1
#RETVAL=ABS(#PARAMETER) // This is an example of using a variable to pass data to a function
#RETVAL=ABS(-1) // This is an example of using a literal.
// In both cased, #RETVAL ends up with the same number.

String Macro Example

When using String data types as literals, you must enclose the string in double quotes ("").

INTEGER:#RETVAL
STRING:#STRNG
#STRNG="String Variable"
#RETVAL=STRLEN(#STRNG)// passing String variable to function
#RETVAL=STRLEN("String Variable") // passing literal string to function
// In both cases, the value of #RETVAL is the same, the length of the string is 15 characters.

Parameter Types

When passing parameters to a function or passing the return value from a function to a variable, you must make sure the variable types match what the macro function expects.

The macro function STRLEN() returns the length, in characters, of a string. It expects that the function parameter is a string literal or variable. It returns an integer.

INTEGER:#IRET
DECIMAL:#DRET
STRING:#SRET
INTEGER:#IPARAM
DECIMAL:#DPARAM
STRING:#SPARAM
#IPARAM=10
#DPARAM=10.0
#SPARAM="10.0"
#IRET=STRLEN(#IPARAM)// Fails, since STRLEN expects a String as the function parameter
#IRET=STRLEN(#DPARAM)// Fails, since STRLEN expects a String as the function parameter
#IRET=STRLEN(#SPARAM)// Works, because #SPARAM is a string
#IRET=STRLEN(10) // Fails, STRLEN expects string, not Integer Literal
#IRET=STRLEN(10.0) // Fails, STRLEN expects string, not Decimal Literal
#IRET=STRLEN("10.0") // Works, because "10.0" is a Literal String.
#SRET=STRLEN(#SPARAM)// Fails, because STRLEN returns an Integer, not a String
#DRET=STRLEN(#SPARAM)// Fails, because STRLEN returns an Integer, not a Decimal
#IRET=STRLEN(#SPARAM)// Again, works because #IRET is an integer variable.

Macro Function/Command Data Types Key

The Macro Functions and Macro Commands topics include a list of all the available macro commands and macro functions. The descriptions for the macro statements include the data type expected for all arguments and the data type returned by the statement.

Example:

I = INT(N)

This description shows the function INT() returns an integer and takes a numeric expression as its parameter.

Rather than spelling out each data type, the following letter codes are used:

Codes for the return values:

Codes for the parameters inside the parenthesis:

Note: - if the function lists no parameter codes inside the parenthesis this indicates no parameters are used.

Specific parameter descriptors:

There are functions where the parameter is more specific than just the general data type. For example:

D=CLR(elmt)

This states that the CLR() function expects an element number or name as its parameter. Additional specific parameter descriptors are listed below.

Related Topics

Arrays

Strings

Macro Development Fundamentals Overview

SmartCAM Automation Overview