defun

AutoCad AutoLISP Functions

 
defun
 
 
 

Defines a function

(defun sym ([arguments] [/ variables...]) expr...) 

Arguments

sym

A symbol naming the function.

arguments

The names of arguments expected by the function.

/ variables

The names of one or more local variables for the function.

The slash preceding the variable names must be separated from the first local name and from the last argument, if any, by at least one space.

expr

Any number of AutoLISP expressions to be evaluated when the function executes.

If you do not declare any arguments or local symbols, you must supply an empty set of parentheses after the function name.

If duplicate argument or symbol names are specified, AutoLISP uses the first occurrence of each name and ignores the following occurrences.

Return Values

The result of the last expression evaluated.

WarningNever use the name of a built-in function or symbol for the sym argument to defun. This overwrites the original definition and makes the built-in function or symbol inaccessible. To get a list of built-in and previously defined functions, use the atoms-family function.

Examples

(defun myfunc (x y) ...)         Function takes two arguments
(defun myfunc (/ a b) ...)       Function has two local variables
(defun myfunc (x / temp) ...)    One argument, one local variable
(defun myfunc () ...)            No arguments or local variables
See Also