next up previous contents index
Next: The deftype Command Up: Data Manipulation Commands Previous: The cross Command   Contents   Index


The define Command

The define command is used to specify user-defined vector functions.

define [function(arg1, arg2, ...)] [=] [expression]
This will define the user-definable function with the name function and arguments arg1, arg2, ... to be expression, which will usually involve the arguments. When the function is called, the arguments that are given are substituted for the formal arguments.

The define command and the .param line in input files can be used to define user-defined functions (UDFs). User-defined function definitions are modularized and prioritized. At the base of the hierarchy (with lowest priority) are the "shell" UDFs which are defined with the define command.

Every circuit has its own set of UDFs, which are obtained from .param lines which are not part of a subcircuit. When a circuit is the current circuit, its UDFs will be searched before the shell UDFs to resolve a function reference. The current circuit's UDF database is pushed onto a stack, ahead of the shell UDFs. Most of the time, this stack is two levels deep.

During initial circuit processing, when subcircuit expansion is being performed, when a subcircuit is bing expanded, any functions defined within the .subckt text with .param lines are pushed on the top of the stack. Since subcircuit definitions may be nested, functions will be pushed/popped according to the depth in the hierarchy currently being processed.

Thus, a function defined in a subcircuit will have priority over a function of the same name and argument count defined in the circuit body, and a function defined in the circuit body will have priority over a function with the same name and argument count defined from the shell with the define command.

When define is given without arguments, all currently defined functions are listed. Those definitions from the current circuit will be shown with an asterisk `*' in the first column. Other functions listed have been defined with the define command. The functions defined in subcircuits are invisible, their use is only transient and they are part of the database only during subcircuit expansion.

If only a function name is given, any definitions for functions with the given name are printed.

It is possible to define a function that calls a non-existing function. The resolution is done when the function is evaluated. Thus, functions of functions can be defined in any order.

Note that one may have different functions defined with the same name but different argument counts. Some useful definitions (which are part of the default environment) are:

define max(x,y) x > y ? x : y
define min(x,y) x < y ? x : y


next up previous contents index
Next: The deftype Command Up: Data Manipulation Commands Previous: The cross Command   Contents   Index
Stephen R. Whiteley 2022-09-18