是否有 SICP 练习的风格指南?

Is there a style guide for SICP exercises?

我目前正在学习 SICP,但我还不太习惯编写 Scheme 代码的风格。是否有任何类型的风格指南可以作为这本书的伴侣?到目前为止,我只找到了in section 1.1.1.

关于“漂亮印刷”的评论

Gerald Jay Sussman, one of the authors of SICP, is also one of the authors of Scheme. Their really cool 1986 video lecture 在 HP,他们不希望 Scheme 如此知名,因此他们将其称为更通用的名称 Lisp。不要混淆,因为 SICP 是 100% 方案,因此方案编码风格将是正确的路径。

Scheme wiki 有一个 style guide together with common variable naming conventions and comment 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:编码风格固执己见。语言不太关心这些,所以这只是为了让代码更容易被人类阅读。