Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!mejac!orchard.la.locus.com!prodnet.la.locus.com!jfr From: jfr@locus.com (Jon Rosen) Newsgroups: comp.lang.pascal Subject: Re: case (string) of Message-ID: <25053@oolong.la.locus.com> Date: 5 Jun 91 15:06:07 GMT References: <1991Jun3.222059.16125@javelin.sim.es.com> <1048.284bd1ff@vger.nsu.edu> Organization: Locus Computing Corp, Los Angeles Lines: 39 In article <1048.284bd1ff@vger.nsu.edu> g_harrison@vger.nsu.edu (George C. Harrison, Norfolk State University) writes: >In article <1991Jun3.222059.16125@javelin.sim.es.com>, tpehrson@javelin.sim.es.com (Tim Clinkenpeel) writes: >> so i can't use case for strings, eh? what are my alternatives? a list of >> if-thens? (tp5.0) >I'm not a TP expert, but Pascal (in general) does not allow nondiscrete types >in case statements. STRING is definitely nondiscrete! >A list of if-then's in not so bad if you structure them correctly. After all >isn't that what case is all about? As an alternative you may want to convert >the string or part thereof to an enumerated type and use a variable of that >type in the case statement; however, in general, this does not allow for >string's that don't conform to the type. Ain't that a drag! When, oh when, will compiler writers and language designers of the Pascal/C mentality wake up and recognize that STRINGS are indeed atomic (i.e., discreet) data types that deserve to be handled the same way integers, floats and bits are... Oh, I know, STRINGS are not REALLY atomic with respect to the underlying processor... But who cares? Neither are sets, but Pascal has a defined fundamental data type for sets... Long integers are not defined on many 16-bit processors but nobody has ever suggested that C programmers ought to write their own functions to handle long integer math! No, this is a real drag that is only partially remedied with languages like C++ where you can do most of what you want to do to make STRINGs a real data type... However, you still can not coerce the compiler itself to adapt all the semantics of your STRING class... In some Pascals (particularly IBM's VS Pascal and Turbo), the CASE statement can be optimized into a jump table in some cases where the range of values is limited... this is easy to check for since only limited range base types are allowed (Integer, enumerated, Char... Floats are also prohibited)... However when the jump table option is not used, the CASE statement turns into a good ole IF-THEN-ELSE internally... Why, then oh why, can't Pascal be defined to allow any type... If it is a limited range type, the jump option is still available... Otherwise, no harm is done and the program looks much neater (and is easier to write)... BTW, PL/I supports the use of ANY data type as the object of a SELECT statement (similar to the CASE/SWITCH statements of PASCAL and C)... Jon Rosen