► |  | Dr Scheme: PLT Programming Environment

1 | Interface Essentials
2 | Languages
3 | Interface Reference
4 | Extending Dr Scheme
| Index

▼ | 1 | Interface Essentials

1.1 | Buttons
1.2 | Choosing a Language
1.3 | Editing with Parentheses
1.4 | Searching
1.5 | Tabbed Editing
1.6 | The Interactions Window
1.7 | Graphical Syntax
1.8 | Graphical Debugging Interface
1.9 | Creating Executables

Version: 4.1.4
top← prev up next →

#### 1.3`` Editing with Parentheses

In Scheme mode, especially, DrScheme’s editor provides special support for managing parentheses in a program. When the blinking caret is next to a parenthesis, DrScheme shades the region between the parenthesis and its matching parenthesis. This feature is especially helpful when for balancing parentheses to complete an expression.

Although whitespace is not significant in Scheme, DrScheme encourages a particular format for Scheme code. When you type Enter or Return, the editor inserts a new line and automatically indents it. To make DrScheme re-indent an existing line, move the blinking caret to the line and hit the Tab key. (The caret can be anywhere in the line.) You can re-indent an entire region by selecting the region and typing Tab.

DrScheme also rewrites parenthesis as you type them, in order to make them match better. If you type a closing parenthesis ), a closing square bracket ], or a closing curley brace }, and if DrScheme can match it back to some earlier opening parenthesis, bracket, or brace, then DrScheme changes what you type to match. DrScheme also rewrites open square brackets, usually to an open parenthesis. There are some exceptions where opening square brackets are not automatically changed to parentheses:

- If the square bracket is after cond-like keyword, potentially skipping some of the sub-expressions in the cond-like expression (for example, in a case expression, the square brackets start in the second sub-expression).

- If the square bracket begins a new expression immediately after a local-like keyword. Note that the second expression after a local-like keyword will automatically become an ordinary parenthesis.

- If the square bracket is after a parenthesis that is after a letrec-like keyword,

- If the square bracket is in a sequence and the s-expression before in the sequence is a compound expression, DrScheme uses the same kind parenthesis, brace, or bracket as before, or

- If the square bracket is in the middle of string, comment, character, or symbol.

The upshot of DrScheme’s help is that you can always use the (presumably unshifted) square brackets on your keyboard to type parenthesis. For example, when typing

(define (length l)
(cond
[(empty? l) 0]
[else (+ 1 (length (rest l)))]))

If you always type [ and ] where any of the square brackets or parentheses appear, DrScheme will change the square brackets to match the code above.

Of course, these features can be disabled and customized in the preferences dialog; see Preferences. Also, in case DrScheme does not produce the character you want, holding down the control key while typing disables DrScheme’s parenthesis, brace, and bracket converter.

top← prev up next →