I'm reading about Swift enum
's in the Swift Programming Language guide and the text was comparing the differences between Swift's enum
and C's enum
. This made me curious as to where enumerations came from originally. I did search online before asking and even asked a few people and they assumed C. (I suppose I'm trying to confirm if enumerations came from C originally.)
我在《Swift编程语言指南》(Swift编程语言指南)中读到了关于Swift enum的内容,文中比较了Swift enum和C enum的区别。这使我对枚举的来源感到好奇。我上网搜索了一下,然后问了几个人,他们都认为是C(我想我是想确认枚举是否来自C)。
Question
问题
What was the first programming language to include enumerations?
第一个包含枚举的编程语言是什么?
2 个解决方案
#1
14
Pascal had enumerated types, but didn't use the keyword enum
. AFAIK, the keyword enum
was first used by C, but the concept is older by quite a margin.
Pascal有枚举类型,但没有使用关键字枚举。关键字enum最初是由C使用的,但是这个概念在很大程度上是旧的。
See Wikipedia on Enumerated type for an example such as:
请参阅Wikipedia关于枚举类型的示例,例如:
type
cardsuit = (clubs, diamonds, hearts, spades);
card = record
suit: cardsuit;
value: 1 .. 13;
end;
var
hand: array [ 1 .. 13 ] of card;
trump: cardsuit;
I think Pascal is the oldest of the languages listed on the Wikipedia page. The LISP referred to is Common Lisp, which postdates Pascal even though original LISP handily pre-dates Pascal.
我认为Pascal是*上列出的最古老的语言。所提到的LISP是普通的LISP,它会对Pascal进行延迟,即使原始的LISP很容易就会对Pascal进行延迟。
The Programming Language Pascal from 1970 lists these types in section 6.1.1 Scalar Types, so for all practical purposes, these enumerated types have always been a part of Pascal. See the documents page at the Standard Pascal web site. The revised report is also available there (1972), and is probably the more widely read document. You can also track Pascal at Wikipedia, of course.
1970年的编程语言Pascal在第6.1.1节中列出了这些类型,因此出于所有实际目的,这些枚举类型一直是Pascal的一部分。请参阅标准Pascal web站点的文档页面。修订后的报告也在那里(1972年),可能是阅读范围更广的文件。当然,你也可以在*上追踪帕斯卡。
(There might be another earlier language with analogous features; I've not identified it, but I've not looked everywhere. Algol-60 was not such a language, though; nor was Fortran or Cobol. Algol-68 and PL/1 are possible contenders.)
(可能还有另一种具有类似特征的早期语言;我还没有确定,但我没有到处找。阿尔戈尔-60并不是一种语言;Fortran或Cobol也不是。algol68和PL/1是可能的竞争者。
#2
2
Algol 68 did not have enums. PL/I did not have enums. Historic Lisp had no notion of compile-time types at all. Algol W and Simula 67 did not have enums. Oddly enough, COBOL is not only a possible contender but the most likely one. Not that it had user-definable types, but look up "88-level". The macro facilities of Burroughs Algol, SAIL, CORAL 66, and RTL/2 could be used to give names to numbers, which takes you almost as far as C's rather broken enums go.
Algol 68没有菊花。我没有枚举。历史Lisp根本没有编译时类型的概念。Algol W和Simula 67没有enum。奇怪的是,COBOL不仅是一个可能的竞争者,而且是最有可能的竞争者。不是说它有用户可定义的类型,而是查找“88级”。Burroughs Algol、SAIL、CORAL 66和RTL/2的宏观设施可以用来给数字命名,这几乎可以让你走到C最坏的地方。
#1
14
Pascal had enumerated types, but didn't use the keyword enum
. AFAIK, the keyword enum
was first used by C, but the concept is older by quite a margin.
Pascal有枚举类型,但没有使用关键字枚举。关键字enum最初是由C使用的,但是这个概念在很大程度上是旧的。
See Wikipedia on Enumerated type for an example such as:
请参阅Wikipedia关于枚举类型的示例,例如:
type
cardsuit = (clubs, diamonds, hearts, spades);
card = record
suit: cardsuit;
value: 1 .. 13;
end;
var
hand: array [ 1 .. 13 ] of card;
trump: cardsuit;
I think Pascal is the oldest of the languages listed on the Wikipedia page. The LISP referred to is Common Lisp, which postdates Pascal even though original LISP handily pre-dates Pascal.
我认为Pascal是*上列出的最古老的语言。所提到的LISP是普通的LISP,它会对Pascal进行延迟,即使原始的LISP很容易就会对Pascal进行延迟。
The Programming Language Pascal from 1970 lists these types in section 6.1.1 Scalar Types, so for all practical purposes, these enumerated types have always been a part of Pascal. See the documents page at the Standard Pascal web site. The revised report is also available there (1972), and is probably the more widely read document. You can also track Pascal at Wikipedia, of course.
1970年的编程语言Pascal在第6.1.1节中列出了这些类型,因此出于所有实际目的,这些枚举类型一直是Pascal的一部分。请参阅标准Pascal web站点的文档页面。修订后的报告也在那里(1972年),可能是阅读范围更广的文件。当然,你也可以在*上追踪帕斯卡。
(There might be another earlier language with analogous features; I've not identified it, but I've not looked everywhere. Algol-60 was not such a language, though; nor was Fortran or Cobol. Algol-68 and PL/1 are possible contenders.)
(可能还有另一种具有类似特征的早期语言;我还没有确定,但我没有到处找。阿尔戈尔-60并不是一种语言;Fortran或Cobol也不是。algol68和PL/1是可能的竞争者。
#2
2
Algol 68 did not have enums. PL/I did not have enums. Historic Lisp had no notion of compile-time types at all. Algol W and Simula 67 did not have enums. Oddly enough, COBOL is not only a possible contender but the most likely one. Not that it had user-definable types, but look up "88-level". The macro facilities of Burroughs Algol, SAIL, CORAL 66, and RTL/2 could be used to give names to numbers, which takes you almost as far as C's rather broken enums go.
Algol 68没有菊花。我没有枚举。历史Lisp根本没有编译时类型的概念。Algol W和Simula 67没有enum。奇怪的是,COBOL不仅是一个可能的竞争者,而且是最有可能的竞争者。不是说它有用户可定义的类型,而是查找“88级”。Burroughs Algol、SAIL、CORAL 66和RTL/2的宏观设施可以用来给数字命名,这几乎可以让你走到C最坏的地方。