是否有SICP练习的样式指南?

问题描述

我目前正在通过SICP进行工作,但是我还不太习惯编写Scheme代码的样式。有没有与本书配套的样式指南?到目前为止,我只发现了in section 1.1.1上有关“漂亮印刷”的评论

解决方法

Gerald Jay SussmanSICP的作者之一,也是Scheme的作者之一。他们在HP的1986 video lecture上确实很酷,他们并不期望Scheme如此出名,因此他们将其称为Lisp。因为SICP是100%方案,所以不要感到困惑,因此方案编码样式将是正确的路径。

Scheme Wiki具有style guide以及常见的variable naming conventionscomment style

Scheme是Lisp的新方言,具有词法闭包和一个命名空间作为核心功能。它使用define代替defundefparameterdefvar。 DrRacket IDE实际上将以“ de”开头的运算符列表视为define。例如。

;;; example procedure test
(define (test arg1 arg2)
  ;; two space indent after define,let and friends
  (if (test? arg1 arg2)                   ; predicates tend to end with ?
      (consequent arg1 arg2)              ; if you split if then arguments align
      (alternative "extra long argument"  ; if you split arguments in procedure call arguments are aligned
                   arg1
                   arg2)))                ; ending parens keep together

在Common Lisp中,大多数编码样式是相同的:

;;; example function test
(defun test (arg1 arg2)
  ;; two space indent after defun,let and friends
  (if (testp arg1 arg2)                   ; predicates tend to end with p
      (consequent arg1 arg2)              ; if you split if then arguments align
      (alternative "extra long argument"  ; if you split arguments in procedure call arguments are aligned
                   arg1
                   arg2)))                ; ending parens keep together

Common Lisp样式的标准参考(包括注释约定)是Peter Norvig和Kent Pitman的Tutorial on Good Lisp Programming Style。您可以将其用作Scheme资源的补充。

PS:编码风格自以为是。该语言对此并不在乎,因此只是为了使人类更容易阅读代码。