comp.lang.ada
 help / color / mirror / Atom feed
* Enumeration I/O
@ 1990-05-08 15:45 Rick Conn
  0 siblings, 0 replies; 6+ messages in thread
From: Rick Conn @ 1990-05-08 15:45 UTC (permalink / raw)


Mike, try
  COLOR_IO.PUT(ITEM => C, SET => COLOR_IO.LOWER_CASE);

It doesn't know where LOWER_CASE is coming from otherwise.

Rick Conn

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Enumeration I/O
  1998-02-10  0:00 Melanie Shatilla
@ 1998-02-09  0:00 ` Matthew Heaney
  1998-02-10  0:00 ` Nick Roberts
  1998-02-10  0:00 ` John J. Cupak Jr.
  2 siblings, 0 replies; 6+ messages in thread
From: Matthew Heaney @ 1998-02-09  0:00 UTC (permalink / raw)



In article <34DF9BBF.9FEA859B@er.uqam.ca>, Melanie Shatilla
<hj791520@er.uqam.ca> wrote:


>I've declared an enumeration type with character literals, and a
>variable of this type, for example :
>    TYPE Symbols is ('%', '$', 'a');

Don't name a type with a plural, unless it refers to a composite object. 
An instance of the Symbol(s) type contains only a single value, so that's
how you should name the type:

type Symbol 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).

That is the defined behavior: character literals print out using the quotes.

>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 ?

You could implement a table:

   type Symbol_Character_Array is
      array (Symbol) of Character;

   function To_Character : constant Symbol_Character_Array :=
     ('%' => '%', 
      '$' => '$', 
      'a' => 'a');
begin
   Text_IO.Put (To_Charcter (Symb));

Another thing you can do is Put the Symbol object to a string, then just
print the middle character of the 3-byte string.

declare
   Symbol_As_String : String (1 .. 3);
   Symbol_As_Character : Character renames Symbol_As_String (2);
begin
  Put (To => Symbol_As_String, Item => Symb);
  Put (Symbol_As_Character);
end;




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Enumeration I/O
  1998-02-10  0:00 Melanie Shatilla
  1998-02-09  0:00 ` Matthew Heaney
@ 1998-02-10  0:00 ` Nick Roberts
  1998-02-11  0:00   ` Ray Blaak
  1998-02-10  0:00 ` John J. Cupak Jr.
  2 siblings, 1 reply; 6+ messages in thread
From: Nick Roberts @ 1998-02-10  0:00 UTC (permalink / raw)



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 ?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Enumeration I/O
  1998-02-10  0:00 Melanie Shatilla
  1998-02-09  0:00 ` Matthew Heaney
  1998-02-10  0:00 ` Nick Roberts
@ 1998-02-10  0:00 ` John J. Cupak Jr.
  2 siblings, 0 replies; 6+ messages in thread
From: John J. Cupak Jr. @ 1998-02-10  0:00 UTC (permalink / raw)
  To: Melanie Shatilla


Melanie Shatilla wrote:
> 
Well, Melanie,

You've gotten a number of interesting answers posted to this newsgroup,
and, I presume, e-mailed to you. All of which address your specific
question: 

> 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;
> 

However, I think that you are declaring and using this information for
a  purpose which you didn't identify. And, because of this, I think that
the correct answer depends on what you're trying to do, rather than what
the problem is with your syntax.

My guess is that you can use a CASE statement to check an input
character, then perform some action(s) based on which character you've
read.

Hope this points you an another direction to look for the answer.

Good luck!

-- 
----------------------------------------------------------------
-                   John J. Cupak Jr, CCP                      -
- Raytheon Electronic Systems: Software Engineering Laboratory -
- tel: 508-858-1222     email (work): jcj@swl.msd.ray.com      -
- fax: 508-858-4336     email (home): jcupak@aol.com           -
----------------------------------------------------------------




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Enumeration I/O
@ 1998-02-10  0:00 Melanie Shatilla
  1998-02-09  0:00 ` Matthew Heaney
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Melanie Shatilla @ 1998-02-10  0:00 UTC (permalink / raw)



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 ?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Enumeration I/O
  1998-02-10  0:00 ` Nick Roberts
@ 1998-02-11  0:00   ` Ray Blaak
  0 siblings, 0 replies; 6+ messages in thread
From: Ray Blaak @ 1998-02-11  0:00 UTC (permalink / raw)



>Melanie Shatilla <hj791520@er.uqam.ca> wrote in article
>>     TYPE Symbols is ('%', '$', 'a');
>>     Symb : Symbols := '$';
[...]
>> 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 ?

  type ImageMap is array (Symbols) of Character;
  TheImageMap : constant ImageMap := ('$' => '$',
                                      '%' => '%',
									  'a' => 'a');
  ...
  Text_Io.Put (TheImageMap(Symb));

Cheers,                                        The Rhythm is around me,
                                               The Rhythm has control.
Ray Blaak                                      The Rhythm is inside me,
blaak@infomatch.com                            The Rhythm has my soul.




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1998-02-11  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1990-05-08 15:45 Enumeration I/O Rick Conn
  -- strict thread matches above, loose matches on Subject: below --
1998-02-10  0:00 Melanie Shatilla
1998-02-09  0:00 ` Matthew Heaney
1998-02-10  0:00 ` Nick Roberts
1998-02-11  0:00   ` Ray Blaak
1998-02-10  0:00 ` John J. Cupak Jr.

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