Schema Coding Style Issues

I got confused in the Scheme style for my code.

Should I format if forms:

but.

if() () () 

or b.

  if () () () 

or c.

 if () () () 

Should I format cond clauses as a.

  cond () () 

or b.

 cond () () 

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

+6
functional-programming lisp scheme
source share
3 answers

Here is a Lisp style guide and here a recommended comment style.

If you have an emacs style editor, enter CMq in your s-expression to format it for you; it will give you correctly formatted code if your line breaks are reasonable (and the editor configuration for indent-alist is not too messed up).

+7
source share

To fill out 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 slightly weaker. When I write thorough code, I do something like this:

 ;;; new section ;;; ;;; section comments (define (fg . x) "docstring goes here" ;; in-function comments (gx)) ; trailing line comment 

But the exact boundaries to use ; vs ;; are changing. In particular, some people (including me) do not really like comments at the end of a line and use it instead ; for comments in the function and ;;; for comments on the section.

+5
source share

Look at Peter Norwig's "A Tutorial on a Good Lisp Style of Programming," although you would find the answer to your specific question in any Scheme / Lisp book.

+5
source share

All Articles