Reputation: 53551
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 ;;?
Upvotes: 6
Views: 1253
Reputation: 2974
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.
Upvotes: 5
Reputation: 18389
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.
Upvotes: 6
Reputation: 41220
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).
Upvotes: 7