Lisp括号(Lisp Parentheses)

编程入门 行业动态 更新时间:2024-10-28 04:22:53
Lisp括号(Lisp Parentheses)

为什么Lispers格式化他们的代码,如样例1所示,而不是如样例2所示? 对我来说(对于大多数来自不同编程背景的人而言,比Lisp),示例2中所示的格式将更容易阅读。 有没有什么特别的原因,Lispers喜欢样品1样式?

样品1

(defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1)))))

样品2

(defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1))) ) )

Why do Lispers format their code like shown in sample 1 instead of as shown in sample 2? To me (and I guess, to most others coming from different programming backgrounds than Lisp), the formatting shown in sample 2 would be easier to read. Is there any particular reason why Lispers prefer the sample 1 style?

Sample 1

(defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1)))))

Sample 2

(defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1))) ) )

最满意答案

LISP IDE环境往往会自动平衡括号,并根据嵌套级别管理缩进。 样本2在这些情况下没有带来任何好处。

在C / FORTRAN / Pascal遗产中,您倾向于强调排序排序(代码解析树更浅和更宽)。 范围结束在您的代码中是一个更重要的事件:因此重点已经在一定程度上更重要。

LISP IDE environments tend to balance parentheses automatically and manage indents based on nesting level. Sample 2 does not bring any advantages in those situations.

In the C/FORTRAN/Pascal heritage, you tend to emphasize sequencing over nesting (code parse trees are shallower and wider). End of scope is a more significant event in your code: hence emphasis has been and still to some extent is more important.

更多推荐

本文发布于:2023-08-06 00:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1440136.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:括号   Lisp   Parentheses

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!