From: Jean-Louis Leroy
Subject: Learning Lisp again
Date: 
Message-ID: <m3puppakf5.fsf@enterprise.newedgeconcept>
Last time I learned (a little) Lisp there was a recommendation that
closing parens should be grouped according to the line that opened
them, i.e.:

(defun occurences (l)
  (let ((res '()))
    (dolist (el l)
      (let ((ass (assoc el res)))
	(if (null ass)
	    (push (cons el 1) res)
	  (incf (cdr ass) 1) ) ) ) ; extra spaces
    res) ) ; extra spaces

...instead of

(defun occurences (l)
  (let ((res '()))
    (dolist (el l)
      (let ((ass (assoc el res)))
	(if (null ass)
	    (push (cons el 1) res)
	  (incf (cdr ass) 1))))
    res))

After 12 years I'm learning Lisp again (more seriously this time ;-)),
using Paul Graham's seemingly excellent book.

I do not see the style rule mentioned above. What's happened to it? Or
did I dream?
-- 
Jean-Louis Leroy
http://users.skynet.be/jll

From: Rudolf Schlatte
Subject: Re: Learning Lisp again
Date: 
Message-ID: <lxk8fx3kvh.fsf@ist.tu-graz.ac.at>
Jean-Louis Leroy <···@skynet.be> writes:

> Last time I learned (a little) Lisp there was a recommendation that
> closing parens should be grouped according to the line that opened
> them, i.e.:

Can you remember what were the advantages to be gained by this?

> (defun occurences (l)
>   (let ((res '()))
>     (dolist (el l)
>       (let ((ass (assoc el res)))
Why are there no spaces here?   ^^^
> 	(if (null ass)
> 	    (push (cons el 1) res)
> 	  (incf (cdr ass) 1) ) ) ) ; extra spaces
The indentation of the three preceding lines is misleading -- the 
(if ...) form is within the scope of (let ...).  
>     res) ) ; extra spaces

[...]

> I do not see the style rule mentioned above. What's happened to it? Or
> did I dream?

I do not see any advantage of this (which does not mean there is none,
of course).

Proper indentation is much more valuable in my opinion, since it makes
program structure apparent.  When I saw your examples, I thought "Odd,
an empty let form" before checking the parens.  Parens are for the
Lisp reader, indentation is for the human reader.  

Fortunately, both paren matching and indentation are taken care of by
a good editor, so one spends less time formatting code and more time
writing it.

Rudi
From: Jean-Louis Leroy
Subject: Re: Learning Lisp again
Date: 
Message-ID: <m33dmla5ah.fsf@enterprise.newedgeconcept>
> Can you remember what were the advantages to be gained by this?

Back then I didn't write enough Lisp to have my own opinion...

It was supposed to make it easier to find the opening parentheses.

> > (defun occurences (l)
> >   (let ((res '()))
> >     (dolist (el l)
> >       (let ((ass (assoc el res)))
> Why are there no spaces here?   ^^^

Because these 3 closing parens are related to open parens on the same
line.

> > 	(if (null ass)
> > 	    (push (cons el 1) res)
> > 	  (incf (cdr ass) 1) ) ) ) ; extra spaces
> The indentation of the three preceding lines is misleading -- the 
> (if ...) form is within the scope of (let ...).  
> >     res) ) ; extra spaces

The indentation is the work of xemacs/lisp-mode/ilisp/mode.

Perhaps the indentations I sent and those you see in your newsreader
differ?

On my side, the (if ...) is indented with respect to the (let ...), as
one would expect. What *I* find misleading is that the two paths in
the (if ...) do not line up.

> Proper indentation is much more valuable in my opinion, since it makes
> program structure apparent.  When I saw your examples, I thought "Odd,
> an empty let form" before checking the parens.  Parens are for the
> Lisp reader, indentation is for the human reader.  

Yes, I agree, however those parens must be put in the right place
otherwise the Lisp reader will bark. One still has to *write* the code
at some point after all <g>
-- 
Jean-Louis Leroy
http://users.skynet.be/jll
From: Pierre R. Mai
Subject: Re: Learning Lisp again
Date: 
Message-ID: <87d7lp77m9.fsf@orion.dent.isdn.cs.tu-berlin.de>
Jean-Louis Leroy <···@skynet.be> writes:

> > Proper indentation is much more valuable in my opinion, since it makes
> > program structure apparent.  When I saw your examples, I thought "Odd,
> > an empty let form" before checking the parens.  Parens are for the
> > Lisp reader, indentation is for the human reader.  
> 
> Yes, I agree, however those parens must be put in the right place
> otherwise the Lisp reader will bark. One still has to *write* the code
> at some point after all <g>

Yes, but writing is very different from reading, because every piece
of code is written much more seldomly than it is read.  For writing,
all Lisp-editors support paren highlighting and paren balancing
commands, which in tandem with automatic indentation based on the list
structure make it very easy to keep the structure Lisp sees in accord
with the structure the reader sees (which is based on indentation
first and foremost).

So writing spaces around parens seems a bit self-defeating for the
purposes of writing, and IMHO it doesn't improve the readability (at
least not sufficiently to weigh up the disadvantages it brings).

Regs, Pierre.

-- 
Pierre Mai <····@acm.org>         PGP and GPG keys at your nearest Keyserver
  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]
From: Jeff Dalton
Subject: Re: Learning Lisp again
Date: 
Message-ID: <x2snuha9dv.fsf@todday.aiai.ed.ac.uk>
Tim Bradshaw <···@cley.com> writes:

> * Jean-Louis Leroy wrote:
> 
> > On my side, the (if ...) is indented with respect to the (let ...), as
> > one would expect. What *I* find misleading is that the two paths in
> > the (if ...) do not line up.
> 
> I *think* this is a historical remnant.  Several maclisp-family lisps,
> of which elisp is probably the only surviving example, have a a syntax
> for IF such that (IF x y z1 z2 z3 ...) would be what is in Common Lisp
> (IF x y (PROGN z1 z2 z3 ...)).  So it makes sense for those Lisps to
> indent IF in this slightly odd way.

Well, almost everything is for historical reasons in the end.

Anyway, I prefer to have the "then" part indented more than the
"else".  I find it more readable, especially in else-if chains,
but maybe that's just because I'm more used to it.

(I started indenting that way just because Emacs did, and also
because the "else" form is in a different category from the "then",
in a minor way.