块的 C 语法背后的基本原理
Rationale behind the C syntax for blocks
我最近试图找到导致在 C 语言和 same family.
像数组的方括号或圆括号这样改变运算符优先级的想法似乎来自 mathematical notation used for these things so it makes sense to me. The semicolon makes sense too, it's meant to separate related sentences with independent clauses,它在 C 中做了类似的事情。
但我找不到类似花括号的东西:它们用于 sets in mathematics, and something somehow similar is their use in musical notation(Ensemble staves),它们用于 表示所有五线谱上的音乐将同时播放(用途不完全相同,但我认为它比它们在数学中的集合更接近)。
此外,我想知道 C 是否真的是第一个引入这种块语法的语言,还是只是为了普及它?
第一个curly brace programming language was BCPL是在1966年,虽然除了{
和}
之外,它还允许$(
和$)
分隔块。
BCPL 基于 CPL which used the unusual (to modern programmers' eyes) §
to open a block and the same symbol with a line through it to close the block. Martin Richards, the inventor of BCPL in "How BCPL evolved from CPL": 说:
CPL used a section symbol (§
) to be equivalent to Algol’s BEGIN
and a
section symbol overprinted with a slash to represent END
. BCPL adopted
$(
and $)
for these tokens and as with CPL such section brackets could
be tagged, allowing a close section bracket to close multiple
sections. Unfortunately this convention lead to rather obscure
programming errors and so when curly brackets ({
and }
) became
available, they were only used as untagged section brackets and the
use of $(
and $)
was discouraged.
花括号通过 B (1969) 进入 C (1972)。
我最近试图找到导致在 C 语言和 same family.
像数组的方括号或圆括号这样改变运算符优先级的想法似乎来自 mathematical notation used for these things so it makes sense to me. The semicolon makes sense too, it's meant to separate related sentences with independent clauses,它在 C 中做了类似的事情。
但我找不到类似花括号的东西:它们用于 sets in mathematics, and something somehow similar is their use in musical notation(Ensemble staves),它们用于 表示所有五线谱上的音乐将同时播放(用途不完全相同,但我认为它比它们在数学中的集合更接近)。
此外,我想知道 C 是否真的是第一个引入这种块语法的语言,还是只是为了普及它?
第一个curly brace programming language was BCPL是在1966年,虽然除了{
和}
之外,它还允许$(
和$)
分隔块。
BCPL 基于 CPL which used the unusual (to modern programmers' eyes) §
to open a block and the same symbol with a line through it to close the block. Martin Richards, the inventor of BCPL in "How BCPL evolved from CPL": 说:
CPL used a section symbol (
§
) to be equivalent to Algol’sBEGIN
and a section symbol overprinted with a slash to representEND
. BCPL adopted$(
and$)
for these tokens and as with CPL such section brackets could be tagged, allowing a close section bracket to close multiple sections. Unfortunately this convention lead to rather obscure programming errors and so when curly brackets ({
and}
) became available, they were only used as untagged section brackets and the use of$(
and$)
was discouraged.
花括号通过 B (1969) 进入 C (1972)。