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:
- 3 - a constant
- #MYINT - a variable
- #MYINT+3 - a variable, an operator, and a constant
- TYP(SEQEL())+100 - a macro function using the value returned from another macro function as its parameter, an operand, and a constant
Examples of decimal expressions:
- 3.0 - a constant
- #MYDEC - a variable
- #DECVAR * 3.0 - a variable, an operator, and a constant
- ENY( #ELNUM ) / ENX( #ELNUM ) - a macro function, an operator, and a macro function
- ATAN( ENY( #ELNUM ) / ENX( #ELNUM ) ) - 180 - a math function with the preceding expression as a parameter, an operator, and a constant
Examples of string expressions:
- "abcd" - a constant
- #MYSTR - a variable
- #MYSTR + "abcd" - a variable an operator and a constant
- REPLACE( #MYSTR, "abc", LEFT( #MYSTR , 3 ) ) - macro string function with variable, constant, and macro string function parameters
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:
- I - returns an integer value.
- D - returns a decimal value.
- S - returns a string value.
Codes for the parameters inside the parenthesis:
- I - indicates the parameter is an integer expression.
- D - indicates the parameter is a decimal expression.
- N - indicates the parameter can be either an integer or decimal expression.
- S - indicates the parameter is a string expression.
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.
- elmt is "element identifier" which can either be an integer expression representing the element number or a string expression representing the element name.
- laynum is "layer number" and is an integer expression.
- stpnum is "step number" and is an integer expression.
- varname is "variable name" and is a string expression.
- wkpln name is "workplane name" and is a string expression.
- path is a Windows path, filename, or path/filename and is a string expression.
Related Topics