Path: utzoo!mnetor!uunet!husc6!cca!g-rh From: g-rh@cca.CCA.COM (Richard Harter) Newsgroups: comp.lang.misc Subject: Re: 0-based/1-based arrays Message-ID: <25831@cca.CCA.COM> Date: 21 Mar 88 17:06:53 GMT References: <25739@cca.CCA.COM> <1106@its63b.ed.ac.uk> Reply-To: g-rh@CCA.CCA.COM.UUCP (Richard Harter) Organization: Computer Corp. of America, Cambridge, MA Lines: 52 Keywords: arrays one zero ordinals In article <1106@its63b.ed.ac.uk> jcb@lfcs.ed.ac.uk (J Bradfield) writes: >In article <25739@cca.CCA.COM> g-rh@CCA.CCA.COM.UUCP (Richard Harter) writes: ... Loose description of ordinals deleted >If we're going to be pedantic and mathematical, let's at least get it right. >The ordinals start at zero: ordinals are defined as equivalence classes of >well-ordered sets, and the smallest ordinal is the order type of the empty >set, to wit, zero. Cardinals are defined either as equivalence classes of >ordinals (all those having the same size), or as the smallest ordinal in >the equivalence class. For example, the smallest infinite cardinal, >aleph-0, is the size of the sequence <0,1,2,...> -- but it's also the size >of the sequence <0,1,2,...,0,1,2,...>, which has twice the length of the >first one. See any book on elementary set theory for more about ordinals >and cardinals. Er, well, no. Ordinals may be defined as equivalence classes of well-ordered sets in set theories which permit this definition. In set theories which do not, e.g. Zermelo Frankel, they are defined quite differently. You are correct that most set theoretic definitions permit an ordinal zero. Transfinite arithmetic may be relevant for usenet discussions, but not programming languages :-). The set theoretic definitions, in any case, are not definitions of ordinals, per se; they are definitions of sets that may be used to instantiate ordinals. There are some fine logical points here that are blissfully ignored in books on elementary set theory. >All this is rather irrelevant to arrays; set theory is not necessarily >a good guide for language designers! True enough. The reason for mentioning ordinals is rather more basic -- people use ordinals all of the time. The problem is really the more simple one that the first element of an array is at displacement zero from the address of the array. Some people conclude from this that counting should start from zero. >Personally, I use whichever base seems more appropriate for the task >in hand---which is why I object to languages that won't let me start >arrays at zero. Since it is (or so it seems to me) that one usually, in programming, want to use indices as displacements, I agree, and would further say that that it is far more useful to have the default start at zero. The problem is that it is rather more natural to think of loop indices as ordinals, i.e. process the first instance, then the second, and so on. Experience says that it is simpler to treat them as displacemnt values. -- In the fields of Hell where the grass grows high Are the graves of dreams allowed to die. Richard Harter, SMDS Inc.