From - Wed Jun 18 10:20:49 1997 From: las@cbgbcs.cb.lucent.com (Larry A Shurr) Newsgroups: comp.emulators.apple2 Subject: Re: Applesoft Basic question... Date: 18 Jun 1997 17:53:33 GMT Organization: Lucent Technologies, Columbus, Ohio Lines: 57 Message-ID: <5o97at$8ns@nntpa.cb.lucent.com> References: <339AF740.7FB6@alcor.concordia.ca> <5o3jf1$b17$1@newsboy.fiber.net> Reply-To: lshurr@lucent.com NNTP-Posting-Host: cbgbcs.cb.lucent.com Path: news2.cais.com!in1.nntp.cais.net!news.hkt.net.!news2.hkt.net!newsgate.cuhk.edu.hk!news-hk.gsl.net!news.gsl.net!news-peer.gsl.net!howland.erols.net!worldnet.att.net!cbgw2.lucent.com!nntphub.cb.lucent.com!not-for-mail In article , Stainless Steel Rat wrote: >-----BEGIN PGP SIGNED MESSAGE----- > >>>>>> "w" == whitneyt writes: >w> 10 Dim a(5,5) >w> 20 a(1,1) = 1 >w> This creates & accesses a two-dimensional array of five elements by >w> five elements. >A common mistake. Applesoft array dimension indices start at 0, not 1, so >a(5,5) is a 6x6 array with 36 cells, not a 5x5 array with 25 cells. Begging your pardon if you know this already: You are correct save that it is true not only for Applesoft, but for many, perhaps most, other Basic dialects, as well (I can't say "all" because I haven't taken an exhaustive survey and there may be exceptions) Apparently, this "feature" dates back to Dartmouth Basic, in which it may have been adopted in order to simplify the indexing arithmetic. 'Course that doesn't sound like such a horrible crime, but it appears that arrays were originally meant to be used to represent vectors in the linear algebra sense where, by convention, subscripts are one-based. Dartmouth Basic and some later offshoots had "matrix" operations designated by the keyword "MAT" for operating on vectors. Thus, one could write statements such as: DIM A(10,10),B(10),C(10,10) MAT C = ZER (Set vector C to all zeros) MAT C = A * B (Multiply vectors A & B, giving C) MAT C = A * Z (Multiply vector A by scalar Z, giving C) and, in keeping with tradition, matrix operations operated on elements whose subscripts start with one, ignoring all of the "zero" elements. Thus, it was still necessary to use "DIM A(5,5)" to declare a 5x5 vector named A even though the resulting array is 6x6. Later Basic dialects adopted the same allocation and indexing strategies for compatibility since there were programs which employed the "feature" and actually used the "zero" elements of arrays. To the best of my knowledge, most personal computer Basics, including all Microsoft Basics (Applesoft is MS Basic V3, if I recall correctly) do NOT have matrix operations built into the language, thus, this historical peculiarity may never have come to your attention before. >Remember: do not waste your 0 indices; they can add up to quite a bit of >memory. Regards, Larry -- Larry A. Shurr (lshurr@lucent.com) I am not interested in email advertising or notices. Please do not send me any. Disclaimer: I do not officially represent Lucent Technologies or Keane, Inc.