[plt-scheme] Paren Paralysis Sufferers Unite

From: John Clements (clements at brinckerhoff.org)
Date: Thu Oct 29 13:41:08 EDT 2009

On Oct 29, 2009, at 10:28 AM, Synx wrote:

>
> Really the only problem I have with parentheses is one of lexical
> context. I personally have a hard time maintaining a stack of  
> context in
> my head, so when I reach a ) I can't easily tell what context I just
> returned to. Matching the closing parentheses /when I type it/ helps,
> but if I'm just looking at code that says
>
> (if (test? a)
>  (if (test? b)
>    ((let ((c (+ a b)))
>       (lambda (d)
>         (+ c d)))
>    b))
>
> I have no clue what that last 'b' is applied to. (it breaks down to  
> (+ a
> b b), right?) So when I encounter ))))))))) (and I frequently do) I  
> have
> to manually count the parentheses and track them back _with my finger_
> to find where to insert a new cond clause for instance. Even if I'm
> looking at my own code!
>
> It's really frustrating. :(

Yikes! don't do that.  I have two suggestions:

1) Unless your e-mailer messed it up, you're not letting drscheme  
indent your code.  Here's what it looks like, indented:

(if (test? a)
     (if (test? b)
         ((let ((c (+ a b)))
            (lambda (d)
              (+ c d)))
          b))

In the drscheme editor, it's now fairly clear what's being applied to  
'b'.

2) Use the s-expression navigation keys!  for instance, suppose the  
cursor is right before the "b", and you're wondering what 'b' is the  
argument to.  Just hit Alt-left (on the Mac, Meta-left on unix, etc.),  
and the cursor goes to the beginning of the first term in the  
application, and it's highlighted, to boot.

It is *really, really* worth getting to know the s-expression  
navigation keys.

3) Tangentially related: if you introduce all your () pairs with ESC- 
(, then you'll never need to type a right paren again. You can  
highlight an s-expression and hit ESC-(, and you'll wrap the term in  
parens.  Going whole hog, you can remap your left-paren to perform  
this operation, and you can get rid of the 'ESC'.

All the best,

John Clements

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2484 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20091029/981dcae6/attachment.p7s>

Posted on the users mailing list.