Passing Parameters to Functions

AutoCAD Visual LISP

 
Passing Parameters to Functions
 
 
 

A better way to convey information from one function to another is to pass parameters to the called function. Design the function so it expects to receive a number of values. Remember the Degrees->Radians function? This function is passed a parameter named numberOfDegrees:

(defun Degrees->Radians (numberOfDegrees) 
(* pi (/ numberOfDegrees 180.0)))

When you call the function, it expects you to pass it a number. The number within Degrees->Radians is declared as the parameter named numberOfDegrees. For example:

_$ (degrees->radians
90)
1.5708

In this case, the number 90 is assigned to the parameter numberOfDegrees.

You can also pass a variable to a function. For example, you might have a variable called aDegreeValue that contains the number 90. The following commands set aDegreeValue and pass the variable to Degrees->Radians:

_$ (setq aDegreeValue
90)
90
_$ (degrees->radians
aDegreeValue)
1.5708