How to balance parentheses in DrRacket
How do I balance parentheses in DrRacket?
When working in DrRacket, it's up to you to make sure your parentheses are balanced. It's your problem to make sure that there are as many right parentheses as right parentheses. Even if you're inclined to Lisp and Scheme, this fact about DrRacket can be, well, terribly annoying. If you've used Paredit in Emacs, for instance, using DrRacket can feel like a step backwards.
DrRacket does have a balanced parentheses feature. It's just disabled by default. Here's how you can turn it on.
Go to the DrRacket preferences. Go to the Editing pane, and then go to the General Editing subpane. There's a checkbox next to
Enable automatic parentheses. Here's a screenshot of what that looks like on DrRacket 6.8 on macOS:
That's all there is to it.
Turning on this feature causes closing parentheses to be automatically included. That means that when you enter (, a matching ) is automatically inserted, and the cursor is put between the two parentheses.
But that's not all.
Automatic parentheses also enables automatic insertion of two other
balanced syntax constructs in Racket:
- string literals: type ", out comes a second "
- square brackets: enter [, out comes ]
Enabling automatic parentheses should improve your experience with DrRacket.