微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决是否有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:编码风格自以为是。该语言对此并不在乎,因此只是为了使人类更容易阅读代码。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。