尖括号 [英] Lisp Parentheses

查看:56
本文介绍了尖括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Lispers像示例1所示而不是示例2所示那样格式化其代码?对我(我想,对于大多数来自与Lisp不同的编程背景的人),示例2中显示的格式将更易于阅读.Lispers偏爱样本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?

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

示例2

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

推荐答案

LISP IDE环境倾向于自动平衡括号并基于嵌套级别管理缩进.在这种情况下,示例2不会带来任何优势.

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.

在C/FORTRAN/Pascal传统中,您倾向于强调排序而不是嵌套(代码解析树更浅,更宽).范围终止是代码中更重要的事件:因此,强调在某种程度上仍然很重要.

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.

这篇关于尖括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆