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 ;;?
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With