免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3833 | 回复: 1
打印 上一主题 下一主题

谁能介绍一下scheme 的小括号和中括号的用法吗? [复制链接]

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-12-20 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-10-09 19:11 |只看该作者 |倒序浏览
看了几天scheme,对他的括号的用法有点迷惑,有没有一个原则什么时候用小括号还是中括号?

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
2 [报告]
发表于 2016-10-09 20:55 |只看该作者
本帖最后由 OwnWaterloo 于 2016-10-09 21:01 编辑

太长不看版: 坚持用小括号。 视觉上区分括号的工作交给编辑器。

R5RS 保留中括号、大括号以及管道符号。

2.3  Other notations
[ ] { } |   Left and right square brackets and curly braces and vertical bar are reserved for possible future extensions to the language.

7.1.1  Lexical structure
The following five characters are reserved for future extensions to the language: [ ] { } |
<delimiter> → <whitespace> ∣ ( ∣ ) ∣ " ∣ ;

schemewiki的faq里也有一条:Is it legal to use square brackets instead of parentheses? 准确说明了使用中括号的坏处。
Thus, Schemes using the above convention are standards-compliant, but code written for them may not be readable by other implementations.

一个允许中括号以及大括号的实现是符合r5rs的。 但如果这样写的程序在别的r5rs上跑不起来, 是程序员自己的锅。


接着是引发混乱的 r6rs 。 允许中括号, 但依然保留大括号。
4.2  Lexical syntax
The following two characters are reserved for future extensions to the language: { }
<delimiter> → ( ∣ ) ∣ [ ∣ ] ∣ " ∣ ; ∣ # ∣ <whitespace>

官方对什么时候可以使用中括号的意见: Use of square brackets


最后是r7rs

管道符号有了新的含义:
2.1. Identifiers
Alternatively, an identifier can be represented by a sequence of zero or more characters enclosed within vertical lines (|), analogous to string literals. Any character, including whitespace characters, but excluding the backslash and vertical line characters, can appear verbatim in such an identifier.

例如这个
  1. |two words|
复制代码
是一个标识符。

又重新将中括号保留:
2.3. Other notations
[ ] { } Left and right square and curly brackets (braces)
are reserved for possible future extensions to the language.

r4rs, r3rs也明确保留中括号和大括号, 没提管道符号。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP