Matching parentheses is easy if you have a decent
text editor. For example, in vi
, you can position the cursor over
a parenthesis and hit %
, and it will scan forward or backward (from an
opening or closing parenthesis, respectively) to find the matching parenthesis
and highlight it, skipping over any matched parenthesis pairs; it will warn
you if no match is found.
Most editors have a feature for matching parentheses. Learn to use it. It's usually easy to get the opening parentheses right, and then if you're in doubt, use the editor to make sure you get the closing parentheses in the right place.
Some editors, like Emacs, have special modes for editing Lisp and Scheme. This feature can be helpful, but just helping match parentheses is the crucial thing for an editor for Scheme. One of the nice things about the Emacs Scheme mode is that it will indent your code automatically if you like, which will show you whether your expressions nest the way they think you do--if you don't get the parentheses right, the text will look funny and tip you off to your error.
(One Emacs mode for Scheme is cmuscheme
, which is available
from the usual sources of Emacs mode code. It's just a set of Emacs
Lisp routines that customizes Emacs to "understand" Scheme syntax
and help you format it. You use the Emacs Lisp package cmuscheme.el
,
and it gives you a handy Scheme editing mode. It's available from
the Scheme Repository.)
Even without a special package, an editor can help you a lot. For example, most modes in Emacs automatically match parentheses, flashing an opening parentheses when you type the corresponding closing parenthesis. A few minutes figuring out how your editor matches parentheses will save you a lot of time.