[plt-scheme] Paren Paralysis Sufferers Unite

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Fri Oct 16 15:55:44 EDT 2009

On Fri, Oct 16, 2009 at 3:29 PM, Morgan <lianciana at gmail.com> wrote:
> Hi,
>
> Newbie here getting used to scheme and getting a whole lota
> "procedure application: expected procedure blah blah blah blah"
> because of missing parens.
>
> How do you all cope emotionally? :-p
>
> More importantly, what survival tricks are there to discovering
> whether there's too few or too many parens? Just knowing the syntax
> backward?
>
> I mean, my nice purple SICP book informs me LISP doesn't give a crap
> about syntax compared to most languages, yet the interpreter throws a
> fit if I've a single pair of superfluous parentheses?
> It just seems a bit unreasonable, c++ and java are entirely happy to
> allow my superfluous parentheses I'm accustomed to using, it can make
> the code easier to read after all.
>
> Discuss :)

So how forgiving are C++ or Java going to be if you put in extra
braces somewhere?  How about brackets?  Or commas, semicolons, colons,
or periods?

The main difference you're running into here is that in Scheme,
parentheses always mean something.  They never just mean "group these
things together".  They [almost] always mean "apply this function".
[And when they don't, they still mean do something.  Never nothing.]

I know it's tricky -- English grammar and high school algebra use
parentheses to group things together, but not really to change their
meaning.  Scheme gives them more meaning.  It's not more or less picky
about syntax than any other language... but it chooses parentheses as
the important part, instead of braces or semicolons or whatever.  Fix
that difference in your mind.

Rule #1: Parentheses mean "apply a function".  If you see (f x y z),
it means apply f to arguments x, y, and z.  If you see (f), it means
apply f to no arguments.  It doesn't just mean f.

There, now you know the syntax backwards and forwards... since there's
just one rule, it's the same both ways!  {...okay, there are a few
more rules, like for "let" and "define".  But 90% of the time, you
want Rule #1.  And even in other cases, parentheses NEVER mean
nothing.}

That, and use a Scheme-conscious editor like DrScheme (or Emacs or vi,
if you're familiar).  When you add the right parenthesis, it will
highlight the corresponding left parenthesis, so you can double check
that you're applying the right function.  Always check that.  If you
open or close parentheses, there must be a function, or something
special like "let" or "define".  Never just grouping.

Good luck with learning Scheme!  It looks a bit different than other
languages, but once you get the hang of it, it's a lot of fun.  And
don't pay too much attention to the curmudgeons on this list, they've
gotten so used to Scheme parentheses they've forgotten there's any
other way of using them.

--Carl


Posted on the users mailing list.