[plt-scheme] Paren Paralysis Sufferers Unite

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Oct 29 16:48:17 EDT 2009

On Oct 29, Synx wrote:
> > 1) Unless your e-mailer messed it up, you're not letting drscheme indent
> > your code.  Here's what it looks like, indented:
> 
> I indented my own code, but it is relatively the same as yours, just
> you inserted 4 spaces instead of 2 to offset the second 'if' and
> 'let' expressions. I forgot how drscheme adds extra space to line up
> the other arguments with the first.

There were two problems in your original indentation:

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

The first is that the last line should be indented by one more space.
The "stack of contexts" is made clear by this -- that last line is a
reference to `b', in the then-branch of a (one-armed) `if', in the
then-branch of another `if'.  The same will hold for using nested
`let's, so overall it's the indentation that makes (or *should* make)
the context clear at all times without any counting.

The second problem is the missing closing paren.  I find it very
difficult to rely on indentation etc when the buffer is not always
balanced, and if the above code was part of some module, then my first
instinct would be to ignore any indentation hints in everything that
follows it.

It's easy to take care of by never inserting an orphan paren -- but in
both drscheme and emacs I do that using `M-('.

(BTW, the 2-spaces for the then/else branches is not a problem, and
IMO it's much better than drscheme's and emacs's default 4 space
indentation.)


> In that sense I like that one lisp paste website, where it
> highlights matching parens simply by hovering your mouse over
> it. (or cursor would be fine too). I don't think that's implemented
> in drscheme though.

It's a cute feature, but I'd hate to use the mouse just to inspect the
structure of code, and I'd also hate being forced to move the mouse to
avoid some distracting hilight that is unrelated to what I'm working
on now.


> When I hold Alt, right and left go from argument to argument in the
> current s-exp, up goes into the context of that expression being an
> argument of something else, and down goes into the current argument
> as if it were an expression. That's very intuitive!

It's also very common -- drscheme borrowed this from emacs (my guess).


> > Going whole hog, you can remap your left-paren to perform this
> > operation, and you can get rid of the 'ESC'.
> 
> I like how emacs can do this (though not so much how they block what
> is seen as improper deletion).

By that you're probably referring to things like paredit, which do
much more than just remap open parens to inserting a balanced pair.
(What these tools are trying to do is keep the buffer balanced at all
times, which is a much more difficult.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!


Posted on the users mailing list.