From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b0d68c502c0ae6 X-Google-Attributes: gid103376,public From: Ehud Lamm Subject: Re: Printing Enum Variable Re: Linux World Date: 1999/03/04 Message-ID: #1/1 X-Deja-AN: 451196890 References: <7bfc2n$jl9@dfw-ixnews5.ix.netcom.com> <7bhh26$r7c$1@remarQ.com> <36DCAC1F.430E2C5E@aasaa.ofe.org> <7bk4v8$kl8$1@remarQ.com> <36DDA761.7B4E8099@aasaa.ofe.org> <7bkrmm$ao1$1@nnrp1.dejanews.com> Content-Type: TEXT/PLAIN; charset=US-ASCII Organization: The hebrew University of Jerusalem Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-03-04T00:00:00+00:00 List-Id: On Thu, 4 Mar 1999 robert_dewar@my-dejanews.com wrote: > Enumeration > types are an important abstraction, and their absence > from C is a significant missing capability. > > Calling something an enum does not make it an enumeration > type! > Time and again I am amazed how this simple festure ofthe language stumps people. I see exercises which show understanding of important and difficult concepts like genericity - but fail to exploit enumeration type where appropriate. This should really end up on my idiom list. Just as the ultimate simple exmaple, for lurkers who are studying the language, consider that when you have a situation where you know exactly the class of possible values enumeration types allow you to (1) name them and (2) implicitly assume that the value is valid, without having to check it each time it is used. Example: If I have a function that receives a coind value, which must be a quarter or a cent, I can coide it like this: type coin is (quarter,cent) ... case Coin_val is when quarter => when cent => end case where as a lower level of abstractenss and more work is needed when you define coin to a integer type: case Coin_val is when 1 => when 25=> when others => raise Coin_Error; end case (This is a nice situation, because many people want to declare an integer subtype with two, non-consecutive values). Ehud Lamm mslamm@pluto.mscc.huji.ac.il http://www2.cybercities.com/e/ehud