comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <Nick.Roberts@dial.pipex.com>
Subject: Re: Enumeration I/O
Date: 1998/02/10
Date: 1998-02-10T00:00:00+00:00	[thread overview]
Message-ID: <01bd3645$3e8b45c0$LocalHost@xhv46.dial.pipex.com> (raw)
In-Reply-To: 34DF9BBF.9FEA859B@er.uqam.ca


Quite possibly, the simplest solution to your problem is to declare

   subtype Symbol is Character;

instead of

   type Symbol is (...);

This way, you lose the 'abstraction', but you gain convenience!  Now all
you need is

   with Ada.Text_IO; use Ada.Text_IO;
   ...
      Symb: Symbol;
   begin
      ...
      Put(Symb);

Easy huh?

Many might contend with me on this.  I'm a big fan of abstraction, make no
mistake, but I do think sometimes it is used when it is not really
appropriate.  In this case, whether my approach is right or wrong really
depends on what the type (strictly, the subtype) 'Symbol' is going to be
used for.

-- 

== Nick Roberts ================================================
== Croydon, UK                       ===========================
==                                              ================
== Proprietor, ThoughtWing Software                   ==========
== Independent Software Development Consultant            ======
== Nick.Roberts@dial.pipex.com                              ====
== Voicemail & Fax +44 181-405 1124                          ===
==                                                            ==
==           I live not in myself, but I become               ==
===          Portion of that around me; and to me             ==
====         High mountains are a feeling, but the hum        ==
=======      Of human cities torture.
===========                             -- Byron [Childe Harold]


Melanie Shatilla <hj791520@er.uqam.ca> wrote in article
<34DF9BBF.9FEA859B@er.uqam.ca>...
> Hi,
> 
> I'm in my second semester of Computer Science and I hope someone can
> help me solve a very basic problem, for which I can't seem to find a
> solution to in any of my textbooks :
> 
> I've declared an enumeration type with character literals, and a
> variable of this type, for example :
>     TYPE Symbols is ('%', '$', 'a');
>     Symb : Symbols := '$';
> 
>     package Symbols_IO is new Text_IO.Enumeration_IO(Symbols);
> 
> When I give the instruction :
>     Symbols_IO.Put(Symb);
> 
> ...I get the right symbol but with the quotes (and I don't want them).
> Obviously, I've thought of writing something like :
> 
>     If Symb = '$' then
>         Text_IO.Put ('$');
>     end if;
> 
> ..but there must be a more convenient way, I hope! Any suggestions
> anyone ?





  parent reply	other threads:[~1998-02-10  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-02-10  0:00 Enumeration I/O Melanie Shatilla
1998-02-09  0:00 ` Matthew Heaney
1998-02-10  0:00 ` Nick Roberts [this message]
1998-02-11  0:00   ` Ray Blaak
1998-02-10  0:00 ` John J. Cupak Jr.
  -- strict thread matches above, loose matches on Subject: below --
1990-05-08 15:45 Rick Conn
replies disabled

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