Product Documentation
Cadence SKILL Language Reference
Product Version IC23.1, November 2023

mprocedure

mprocedure( 
s_macroName( 
s_formalArgument 
) 
g_expr1 ... 
)
=> s_funcName

Description

Defines a macro with the given name that takes a single formal argument. This is a syntax form.

The body of the macro is a list of expressions to be evaluated one after another. The value of the last expression evaluated is considered the result of macro expansion and is evaluated again to get the value of the macro call.

When a macro is called, s_formalArgument is bound to the entire macro call form, that is, a list with the name of the macro as its first element followed by the unevaluated arguments to the macro call.

Macros in SKILL are completely general in that a macro body can call any other function to build an expression that is to be evaluated again.

A macro call within a function definition is expanded only once, when the function is compiled. For this reason, be cautious when defining macros. sure they are purely functional, that is, side-effects free. You can use expandMacro to verify the correct behavior of a macro definition.

Arguments

s_macroName

Name of the macro function.

s_formalArgument

Formal arguments for the macro definition.

g_expr1

A SKILL expression.

Value Returned

s_funcName

Name of the macro defined.

Examples

mprocedure( whenNot(callForm)
‘(if !,(cadr callForm) then ,@(cddr callForm)))
=> whenNot
expandMacro( '(whenNot x>y z=f(y) x*z))
=> if(!(x>y) then (z=f(y)) (x*z))
whenNot(1>2 "Good")
=> "Good"

Related Topics

Function and Program Structure

defmacro


Return to top
 ⠀
X