comp.lang.ada
 help / color / mirror / Atom feed
From: Magnus Larsson <mla@omicron.se>
Subject: Re: Printing Enum Variable Re: Linux World
Date: 1999/03/04
Date: 1999-03-04T00:00:00+00:00	[thread overview]
Message-ID: <36DE3744.13F6A16A@omicron.se> (raw)
In-Reply-To: 36DDA9BA.E005E578@aasaa.ofe.org

I think the Reading of an Enum is really the trick in Ada, and find
these type of constructs really useful. Note that you could declare the
State type in your "language package" which is precicely what I've used
it for. Here you don't have care about any caps. My only problem is the
latin-1 characters in DOS, but I guess that's no fault of Ada. ;-)

/Magnus

   function State
        (Data       : String)
         return Natural
   is
      type State is (Brake, Start, Resume, Reset); 
   begin
      return State'Pos (State'Value (Data));
   exception
      when others => -- Of course i should only trap the "right"
exception,
                     -- but I can't remember which one it was
         return Some_Error_Code;
   end State;


David Starner wrote:
> 
> Fraser Wilson wrote:
> > Well, I have to disagree on this.  Printing a string representation of
> > a literal is not something that goes out to the User (bless his heart).
> > It's for my information, and the all caps, direct representation of the
> > name is exactly what I need.
> 
> Actually, it rather annoyed me to find it in all caps. I typed into the
> program with initial caps for a reason. If it's not something that goes
> out to a user, why worry about it? For most my enumeration printing in
> C, a couple nested "?:" did the trick.
> >
> > I understand gdb can do something similar, but debuggers are a poor
> > substitute for understanding the code.
> How does this help you understand the code?
> >
> > If you add an extra element to the enumeration, will the compiler
> > warn you about the switch statement?  What if the strings were stored
> > in an array?
> Yes, if you added a default case at the end of the switch statement. The
> array is a totally different issue - a valid point to complain about.
> >
> > >IMO, printing enumerator literals, as is, is a quick and dirty hack that
> > >should be used only if you're the only user.
> >
> > Again, it's for my eyes only.  And I wouldn't call it a quick'n'dirty hack.
> > It's a useful technique.
> If it is just something I toss into a program and don't care how it
> looks or runs, just that it does, that's what I call a quick'n'dirty
> hack. YMMV
> >
> > > (How should you print a value that doesn't have an
> > >associated name, for instance?)
> >
> > I'd completely forgotten you could do that in C.  So an enum is basically
> > a shorthand to avoid writing lots of #defines?  Doesn't that somewhat miss
> > the point.
> 
> No, it just means that a C enum is not quite the same abstraction as an
> Ada enum.
> --
> David Starner - OSU student - dstarner98@aasaa.ofe.org
> If you want a real optimist, look up Ray Bradbury. Guy's nuts.
> He actually likes people. -David Brin

-- 
________________________________
 .|,    | Jobb: 08 - 750 74 30
 -o---- | Mob : 0708 - 13 57 94
omicron | Hem : 08 - 545 600 76




  parent reply	other threads:[~1999-03-04  0:00 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-02  0:00 Linux World Richard D Riehle
1999-03-02  0:00 ` fraser
1999-03-02  0:00   ` Printing Enum Variable " David Starner
1999-03-03  0:00     ` fraser
1999-03-03  0:00       ` David Starner
1999-03-03  0:00         ` Samuel T. Harris
1999-03-03  0:00         ` fraser
1999-03-04  0:00         ` dennison
1999-03-04  0:00           ` Ehud Lamm
1999-03-04  0:00         ` robert_dewar
1999-03-03  0:00           ` David Starner
1999-03-04  0:00             ` Samuel Mize
1999-03-04  0:00               ` Samuel Mize
1999-03-05  0:00                 ` Robert A Duff
1999-03-05  0:00               ` Robert A Duff
1999-03-07  0:00               ` Florian Weimer
1999-03-07  0:00                 ` Michael Young
1999-03-07  0:00                   ` Larry Kilgallen
1999-03-07  0:00                     ` Michael Young
1999-03-08  0:00                       ` Larry Kilgallen
1999-03-08  0:00                         ` robert_dewar
1999-03-08  0:00                       ` Florian Weimer
1999-03-08  0:00                       ` robert_dewar
1999-03-08  0:00                         ` Richard D Riehle
1999-03-09  0:00                           ` Michael Young
1999-03-09  0:00                             ` Larry Kilgallen
1999-03-09  0:00                               ` Michael Young
1999-03-10  0:00                                 ` Mike Silva
1999-03-09  0:00                               ` billy
1999-03-10  0:00                                 ` Pascal Obry
1999-03-10  0:00                                 ` robert_dewar
1999-03-10  0:00                                   ` Dale Stanbrough
1999-03-10  0:00                                     ` Pascal Obry
1999-03-10  0:00                                     ` Richard D Riehle
1999-03-10  0:00                                     ` dennison
1999-03-10  0:00                                       ` bob
1999-03-10  0:00                                         ` Mike Silva
1999-03-10  0:00                                           ` Nick Roberts
1999-03-10  0:00                                           ` dennison
     [not found]                               ` <7c4ru6$e45$1@remarq.com>
1999-03-10  0:00                                 ` fraser
     [not found]                               ` <7 <7c58qa$b6b$1@cf01.edf.fr>
1999-03-10  0:00                                 ` fraser
     [not found]                             ` <1999Mar9.131659. <dale-1003991644340001@r1021c-07.ppp.cs.rmit.edu.au>
1999-03-10  0:00                               ` Larry Kilgallen
1999-03-07  0:00                   ` Matthew Heaney
1999-03-08  0:00                     ` Michael Young
1999-03-08  0:00                       ` Matthew Heaney
1999-03-04  0:00             ` robert_dewar
1999-03-04  0:00           ` Ehud Lamm
1999-03-05  0:00             ` Richard D Riehle
1999-03-05  0:00               ` Nick Roberts
1999-03-06  0:00                 ` Ehud Lamm
1999-03-06  0:00                   ` robert_dewar
1999-03-06  0:00                     ` Ehud Lamm
1999-03-06  0:00                     ` Larry Kilgallen
1999-03-06  0:00                       ` Dave Taylor
1999-03-06  0:00                         ` Bruce or Tracy
1999-03-03  0:00     ` Fraser Wilson
1999-03-03  0:00       ` David Starner
1999-03-04  0:00         ` robert_dewar
1999-03-04  0:00         ` Richard D Riehle
1999-03-04  0:00         ` fraser
1999-03-05  0:00           ` Nick Roberts
1999-03-05  0:00             ` fraser
1999-03-04  0:00         ` Magnus Larsson [this message]
1999-03-03  0:00           ` Printing Enum Variable Re: Linux World (Correction) Hans Marqvardsen
1999-03-03  0:00           ` Printing Enum Variable Re: Linux World Hans Marqvardsen
1999-03-04  0:00             ` Nick Roberts
1999-03-04  0:00             ` robert_dewar
1999-03-04  0:00               ` Hans Marqvardsen
1999-03-05  0:00                 ` dewar
1999-03-07  0:00                   ` Hans Marqvardsen
1999-03-04  0:00               ` Hans Marqvardsen
1999-03-05  0:00                 ` Larry Kilgallen
1999-03-05  0:00                 ` dewar
1999-03-05  0:00                   ` David Botton
1999-03-05  0:00                     ` robert_dewar
1999-03-04  0:00         ` Richard D Riehle
1999-03-03  0:00     ` Larry Kilgallen
1999-03-03  0:00       ` Nick Roberts
1999-03-03  0:00         ` David Starner
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox