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.)
What was the first programming language to include enumerations?
-
4Swift's "enum" is actually a union type.Kasey Speakman– Kasey Speakman2015年10月07日 16:18:36 +00:00Commented Oct 7, 2015 at 16:18
2 Answers 2
Probably Lisp (1958).
In Lisp dialects, symbols can be used in the same way as C's enumerations. Indeed, the Wikipedia page for Symbol (Programming) says:
In the most trivial implementation, [symbols] are essentially named integers (e.g. the enumerated type in C).
Scheme and Common Lisp have a member
function, which can be used like:
(member 'b '(a b c))
;=> (b c)
Fortran also has an enumeration type, but it looks like it was added in Fortran2003 for compatibility with C's enum
, which itself was only added in ANSI C (1989).
-
1In particular, you can define an enumerated type:
(deftype bool () '(member true false file-not-found))
(ref. TheDailyWTF). That can be used to check the type of your values withtypep
.coredump– coredump2015年10月07日 16:49:54 +00:00Commented Oct 7, 2015 at 16:49
In the strict sense, the answer is probably Pascal. Pascal certainly had enumerated types before C did. Algol 60, Algol W, Burroughs Algol, Simula 67, and Algol 68, Pascal's more noteworthy predecessors, did not. In a somewhat weaker sense, COBOL "88-level" definitions are not completely utterly and entirely unlike enumerations; you could say that the germ of the idea was there (more than in Lisp).
-
2Can you edit in some references to back up your statement?Jan Doggen– Jan Doggen2016年02月26日 09:55:28 +00:00Commented Feb 26, 2016 at 9:55