AutoLISP uses parentheses more frequently than most other computer languages. One of the most frequent syntax errors in AutoLISP is an unequal number of open and close parentheses. VLISP includes a number of tools to help you detect unbalanced or unmatched parentheses.
, the VLISP code formatter searches for unbalanced parentheses when it formats your code. If you allow it to, the formatter will add parentheses where it thinks they are missing. Typically, though, the VLISP formatter adds parentheses at the end of a program, not to where you really need them. If you let VLISP add the parentheses, you will probably have to remove them later.As noted in
In any event, you must check the structure of your program to determine where the parentheses are really missing. You can use these parentheses matching items from the Edit menu to help you find unbalanced parentheses:
Moves the insertion point (marked by the cursor) just past the close parenthesis that matches an open parenthesis.
If the current cursor position is just before an open parenthesis, VLISP matches that parenthesis with its closing parenthesis. If the cursor position is in the middle of an expression, VLISP matches the current expression's open parenthesis with its closing parenthesis.
Moves the insertion point to just before the open parenthesis that matches a close parenthesis.
If the current cursor position is just after a close parenthesis, VLISP matches that parenthesis with its opening parenthesis. If the cursor position is in the middle of an expression, VLISP matches the current expression's close parenthesis with its open parenthesis.
Moves the insertion point as the Match Forward command does, but also selects all text between the start and end positions.
With the cursor positioned right before an open parenthesis, double-clicking also selects all text up to the matching close parenthesis, but does not move the insertion point.
Moves the insertion point as the Match Backward command does, but also selects all text between the start and end positions.
With the cursor positioned right after a close parenthesis, double-clicking also selects all text up to the matching open parenthesis, but does not move the insertion point.
For example, look at the following code:
1 (defun yinyang (/ origin radius i-radius half-r origin-x origin-y)
2 (setq half-r (/ radius 2))
3 (setq origin-x (car origin))
4 (setq origin-y (cadr origin))
5 (command "_.CIRCLE"
8 (command "_.ARC"
10 (list origin-x (+ origin-y half-r))
11 (list origin-x (+ origin-y radius))
14 (command "_.ARC"
16 (list origin-x (- origin-y half-r))
17 (list origin-x (- origin-y radius))
(The line numbers are not part of the text; they are used to help explain the example.)
Here is what happens if you load this code in VLISP and continually issue the Match Forward command, starting with the insertion point at the beginning of line 1.
defun. Notice also that all the statements after line 5 are indented in a manner unlike in the preceding program code. These two clues indicate something is amiss at this point in the program. In fact, the close parenthesis to the command that begins on line 5 is missing.In other words, the close parenthesis that matches the open parenthesis on line 5 is the last parenthesis in the program. You know this is an error because the last close parenthesis in an AutoLISP program should match the open parenthesis of the program's