unj*_*nj2 6 lisp scheme functional-programming
我对我的代码的Scheme样式感到困惑.
我应该格式化表格如下:
一个.
if()
  ()
  ()
或b.
  if () ()
        ()
或c.
if () () ()
我应该将cond条款格式化为
.
  cond ()
       ()
或b.
cond
()
()
我什么时候使用单身; 评论和双重;;?
要填写Doug针对您的具体问题的答案:
(if test
    then
    else)
(cond
  (test1 exp1)
  (test2 exp2)
  (else exp3))
或者,对于具有长系列表达式的conds:
(cond
  (test1
   exp1
   exp2)
  (else
   exp3
   exp4))
评论惯例有点宽松.当我编写细致的代码时,我会这样做:
;;; new section ;;;
;;; section comments
(define (f g . x)
  "docstring goes here"
  ;; in-function comments
  (g x)) ; trailing line comment
但;vs ;;使用的确切界限各不相同.特别是,有些人(包括我)不太喜欢尾随行注释,而是;用于函数内注释和;;;部分注释.