> I'd be all for having clojure-fmt that would format clojure code
> in the way Rich prefers it so that when I get random code I could
> convert it to a nice and predictable format. It should be even
> simpler to write for a lisp than other languages.

See Guy Steele "Common Lisp, The Language" pp748-769 "Pretty Printing"

"This facility is the culmination of thirteen years of design, testing,
revision and use of this approach" -- Steele

This problem has a long history and a lot of thought in the lisp community.
It would be trivial to have slime automatically prettyprint every expression.
It would be trivial to define a "canonical style" for clojure.

The problem isn't technical at all. The problem is social. Actually, the
"problem" is that I don't know any lispers who could consider it a "problem"
worth thinking about, although they spent 13 years "not" thinking about it.

Prettyprinting lisp code is a homework assignment.
Getting every lisper to agree is a United Nations summit meeting.

There are so many things you can "think" in lisp that you can't even
"think" in other languages. For instance,

define a function....

   (defun foo () ....)

define private variables only accessible to certain functions

   (let (x)
     (defun foo1 () x)
     (defun foo2 () x)

define "classes" with private variables and local methods

(defun classname ()
  (let (x)
    (defun method () x)))

define "modules" with global private variables, "classes"
and private variables local to the "classes".

(let (y)
 (defun class1 ()
    (let (x-class1-private)
       (defun class1-method-1 () )
       (defun class1-method-2 () )))
 (defun class2 ()
    (let (x-class2-private)
       (defun class2-method-1 () )
       (defun class2-method-2 () ))))

It is possible to do all of that without using any new language
extentions. Java won't allow naked functions and I don't see a
way to make "modules" except with compile-time package naming.
Python has different, but equally limiting, restrictions on what
you can think and how you can think about it.

Lisp allows you to think of these ideas and then write code
to structure the ideas. The layout of the code mirrors the ideas.

As in architecture, "Form follows function" and lisp allows you
complete freedom of both so I don't think you can ever define a
"form" that will be useful and general.

Now we come to the debate about "style". The indentation
shown above has meaning in that it shows you what I intended for
each level of structure. If your "pretty-printer" says that all
(defun) forms (well, (defn) forms) are "required" to start in
column 1 then this loses the semantics of my nesting. There are
no general rules that cover all of the things I can think in lisp.
That makes lisp completely different from python or java.

The ONLY general rule about lisp code formatting I know is that
"the other guy's code is badly formatted" :-)

Tim Daly




Daniel Gagnon wrote:

       a) Python doesn't really have this problem


Python doesn't have this problem because the canonical style is define by PEP 8 and Pythonistas love simplicity through conventions.

PEP 8: http://www.python.org/dev/peps/pep-0008/

I think it's actually a great feature of the language, I almost never got code that didn't match or nearly matched PEP 8. Google's go goes even further by having the canonical style define by gofmt. Once your code is written, you run it through gofmt and it turns canonical. If your code doesn't look nice after gofmt, you must file a bug against gofmt rather than hand tweak the formatting.

I'd be all for having clojure-fmt that would format clojure code in the way Rich prefers it so that when I get random code I could convert it to a nice and predictable format. It should be even simpler to write for a lisp than other languages.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to