views:

205

answers:

3

I am confused about the Scheme style for my code.

Should I format if forms as:

a.

if()
  ()
  ()

or b.

  if () ()
        ()

or c.

if () () ()

Should I format cond clauses as
a.

  cond ()
       ()

or b.

cond
()
()

When do I use a single ; to comment and a double ;;?

+5  A: 

Here is a Lisp style guide, and here is a recommended commenting style.

If you have an emacs style editor, typing C-M-q within your s-expression should format it for you; it will get you correctly formatted code if your line breaks are reasonable (and editor configuration for indent-alist hasn't been munged too badly).

Doug Currie
+4  A: 

To fill in Doug's answer for your specific questions:

(if test
    then
    else)

(cond
  (test1 exp1)
  (test2 exp2)
  (else exp3))

Or, for conds with long series of expressions:

(cond
  (test1
   exp1
   exp2)
  (else
   exp3
   exp4))

Comment conventions are a little looser. When I am writing careful code, I do something like this:

;;; new section ;;;
;;; section comments


(define (f g . x)
  "docstring goes here"
  ;; in-function comments
  (g x)) ; trailing line comment

But the exact boundaries for ; vs ;; usage vary. In particular, some people (including me) do not much like trailing line comments and will instead use ; for in-function comments and ;;; for section comments.

Nathan Sanders
Note that most schemes don't have "doc-strings".
Eli Barzilay
+3  A: 

Have a look at Peter Norvig's "Tutorial on Good Lisp Programming Style" though you would have found the answer to your particular question in any Scheme/Lisp book.

Luís Oliveira