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

defun

defun( 
s_funcName 
( l_formalArglist ) 
g_expr1 ... 
)
=> s_funcName

Description

Defines a function with the name and formal argument list you specify. This is a syntax form.

The body of the procedure is a list of expressions to be evaluated one after another when s_funcName is called. There must be no white space between defun and the open parenthesis that follows.

However, for defun there must be white space between s_funcName and the open parenthesis. This is the only difference between the defun and procedure forms. defun has been provided principally so that you can  your code appear more like other LISP dialects.

Expressions within a function can reference any variable on the formal argument list or any global variable defined outside the function. If necessary, local variables can be declared using the let function.

Arguments

s_funcName

Name of the function you are defining.

l_formalArglist

Formal argument list.

g_expr1

Expression or expressions to be evaluated when s_funcName is called.

Several parameters provide flexibility in procedure argument lists. These parameters are referred to as @ (“at” sign) options. The parameters are @rest, @optional, @key, and @aux. See procedure for a detailed description of these argument list parameters.

Value Returned

s_funcName

The name of the function being defined.

Examples

procedure( cube(x) x**3 )    ; Defines a function to compute the
=> cube ; cube of a number using procedure.
cube( 3 ) 
=> 27
defun( cube (x) x**3 )       ; Defines a function to compute the 
=> cube ; cube of a number using defun.

The following function computes the factorial of its positive integer argument by recursively calling itself.

procedure( factorial(x)
if( (x == 0) then 1
else x * factorial(x - 1)))
=> factorial
defun( factorial (x)
if( (x == 0) then 1
else x * factorial( x - 1)))
=> factorial
factorial( 6 )
=> 720

Related Topics

Function and Program Structure

let


Return to top
 ⠀
X