

Examples of Lisp formatting through history - hadronzoo
http://kazimirmajorinc.blogspot.com/2012/03/few-examples-of-lisp-code-typography.html

======
siavosh
Interesting. Two trends I pick up on at glance: 1) increased use of
indentation 2) abandoning commenting for self-documenting code (and the
occasional header comment). I'm guessing these are pretty universal trends,
no?

------
hollerith
Coding in Haskell changed the way I indent Lisp code. The way I intent now
differs from most Lisp indentation styles in that

    
    
      (a (b (c (d (e
        (f (g (h xxx yyy (i uuu (vv ww qq) (j
          foo bar))))))))))
    

becomes allowed whereas

    
    
      (let ((a b)
            (c d))
        foo)
    

becomes not allowed -- you have to write it as

    
    
      (let
        ((a b)
          (c d))
        foo)
    

or (if you need the let clauses to line up) as

    
    
      (let
        (
          (a b)
          (c d))
        foo)
    

Well, the let form is such a unusual case that I will give a second example:

    
    
      (f (g xxx
            yyy)
         zzz)
    

becomes not allowed -- you have to write it as

    
    
      (f
        (g xxx
          yyy)
        zzz)
    

or (if you need g's arguments to line up) as

    
    
      (f
        (g
          xxx
          yyy)
        zzz)
    

Although I used two spaces for every new level of indentation above, the
choice of the number 2 is of course not an essential element of the style.

~~~
dustingetz
i'm not sure think your personal take on lisp indentation has any compelling
benefits to justify departing from consensus.

i recognize a lot of old school lispers follow a philosophy of "lisp empowers
me so much that i don't need a team", so they do whatever they want and their
productivity so godly that nobody says anything, but this isn't particularly
helpful to increased lisp adoption, which benefits us all. maybe it isn't
harmful either, but we who are already using it aren't in a position to judge
this.

~~~
cheatercheater
What are you talking about, he's using standard banner-style-indent with lisp-
close-brackets (i.e. the closing brackets are on the last line of the body,
not below the body)

I use banner style in all languages and it works well.

~~~
hollerith
In that case, if you use Emacs, perhaps you'd like to see the Emacs Lisp that
I have bound to my tab key (which however has not been made to work with non-
Lisp-syntax languages).

If you write "(a (b (c (d (e (f" RET, TAB indents just as many spaces as it
would if you had written just "(a" RET.

~~~
cheatercheater
Sounds cool. I don't use emacs at all, but maybe you can post it anyways?

~~~
hollerith
Now that I know you see replies to your comments, I will inform you that I
disagree with your assertion that what I have been describing here is just
banner style.

Lisp coders are accustomed to a certain pattern of indentation that would be
analogous to the following in C, where xxx and yyy are typically many lines
long:

    
    
      while(aa){if(bb){
                    xxx}
          yyy}
    

I am recommending for Lisp coders to avoid that pattern and to indent the
above as follows:

    
    
      while(aa){
          if(bb){
              xxx}
          yyy}
    

which is of course familiar to a C programmer and which we will refer to as
"formula A". However, what will be unfamiliar to a C programmer is the motive
behind my recommendation: namely, to make it possible to introduce into Lisp a
new pattern of indentation, unfamiliar to C programmers and Lisp programmer
(but familiar to Haskell programmers) in which you are allowed to write,

    
    
      while(aa){if(bb){
          xxx}}
    

where again xxx is a place holder for many lines of code. However, it is
important to note that the following would be a definite violation of the
indentation style I recommend:

    
    
      while(aa){if(bb){
          xxx}
          yyy}
    

I recommend indenting that as formula A above. In other words, you can begin
multiple multi-line s-expressions on the same line, but if you do, you have to
close all of those multi-line s-expressions at the same time.

>maybe you can post it anyways?

It's a little too long: about 90 lines of code. I could make it shorter by
taking out the code that warns the user of the stylistic violation described
above, but most user would want that code.

~~~
dustingetz
i'm quite confused, I'd love to read a blog post with side-by-side examples in
both C-style and lisp, in both styles, laying out the benefits.

------
drcode
I wrote my own indenter in EMACS for clojure 'cause I don't like the standard
indentation of modern lisps. My indenter uses the "primitive" syntax-level
indentation exemplified by the "Dream of a lifetime" code example from 1979 on
this page.

This is the ONE AND ONLY CORRECT INDENTATION STYLE for Lisp.

~~~
lemming
_This is the ONE AND ONLY CORRECT INDENTATION STYLE for Lisp._

Because the defining feature of Lisp is allowing only one way to do things?

~~~
gee_totes
I thought the defining feature of Lisp was the meta-programming. Or am I
missing some sarcasm?

~~~
roryokane
Yes, lemming's comment is sarcastic.

------
WildUtah
Look at all the commas!

Clojure has been ahead of the curve on these commas, of course. Commas (and
semicolons) are considered whitespace. They're available to pretty up your
code's presentation however you like. It's like Clojure is committing in
advance not to need many syntax characters.

~~~
pwpwp
Ahead of the curve? Other Lisps stopped using commas half a century ago.

------
roryokane
Link to the last example, from "Introduction to Newlisp, wikibook, 2012":

[http://en.wikibooks.org/wiki/Introduction_to_newLISP/Macros#...](http://en.wikibooks.org/wiki/Introduction_to_newLISP/Macros#Symbol_confusion)

------
jhrobert
Is this the definite proof that Lisp in unreadable, no matter what?

~~~
davidw
The standard joke about how Lisp looks, which I believe comes from Perl's
Larry Wall, is "oatmeal and toenail clippings".

It's interesting to see the old ones even if one is not a big lisp fan,
though.

------
kinleyd
A very cool history of Lisp: while we see the changes in formatting styles
over the years, we also see the personalities behind the progress of Lisp.
Really nice!

------
larsberg
Not all samples have numbers in them, but I was somwhat disturbed that it was
not until 2012 that the LISP publishers used a monospace font that clearly
distinguished 0 "zero" and O "capital letter o".

------
pmcjones
A number of the documents he excerpted are available via
<http://www.softwarepreservation.org/projects/LISP/> .

------
swang
This is almost impossible to read on an iPhone. The text doesn't resize and
whenever I try to scroll around it activates some blogger "next article"
functionality

~~~
arto
Likewise on an Android. Made for difficult reading.

------
mark_l_watson
That was fun, but he missed InterLisp D. I got an Xerox 1108 Lips Machine in
1982, and InterLisp D was amazing!

~~~
pmcjones
It's there: [http://instprog.com/blogposts/Few-Examples-of-Lisp-Code-
Typo...](http://instprog.com/blogposts/Few-Examples-of-Lisp-Code-
Typography/1985.png)

