An AutoLISP program consists of a series of expressions. AutoLISP expressions have the following form:
(function arguments)
Each expression begins with an open (left) parenthesis and consists of a function name and optional arguments to that function. Each argument can also be an expression. The expression ends with a right parenthesis. Every expression returns a value that can be used by a surrounding expression. The value of the last interpreted expression is returned to the calling expression.
For example, the following code example involves three functions:
(fun1 (fun2 arguments)(fun3 arguments))
fun1, has two arguments, and the other functions, fun2 and fun3, each have one argument. The functions fun2 and fun3 are surrounded by function fun1, so their return values are passed to fun1 as arguments. Function fun1 evaluates the two arguments and returns the value to the window from which you entered the code.
If you enter this code at the Visual LISP Console prompt or the AutoCAD Command prompt, the AutoCAD AutoLISP interpreter processes the code. The first function,* (multiplication) function, which accepts one or more numbers as arguments:
The following example shows the use of the_$β(*β2β27)
54
Because this code example has no surrounding expression, AutoLISP returns the result to the window from which you entered the code.
+ (addition) function as one of the arguments for the * (multiplication) function.
Expressions nested within other expressions return their result to the surrounding expression. The following example uses the result from the_$β(*β2β(+β5β10))
30
If you enter the incorrect number of close (right) parentheses, AutoLISP displays the following prompt:
(_>
The number of open parentheses in this prompt indicates how many levels of open parentheses remain unclosed. If this prompt appears, you must enter the required number of close parentheses for the expression to be evaluated.
_$β(*β2β(+β5β10
((_> ) )
30
A common mistake is to omit the closing quotation mark (") in a text string, in which case the close parentheses are interpreted as part of the string and have no effect in resolving the open parentheses. To correct this condition, press SHIFT + ESC to cancel the function, then re-enter it correctly.