comp.lang.ada
 help / color / mirror / Atom feed
* Enumeration_IO
@ 1990-05-08  0:41 Mike Feldman
  1990-05-08 16:38 ` Enumeration_IO Alex Blakemore
  1990-05-08 23:53 ` Enumeration_IO M Y Ben Gershon
  0 siblings, 2 replies; 11+ messages in thread
From: Mike Feldman @ 1990-05-08  0:41 UTC (permalink / raw)


In preparing some programs for a book I am working on, I have gotten
interested in the idiosyncracies of Enumeration_IO. Specifically, the
PUT operations in this generic package are supposed to have a parameter
SET of type TYPE_SET, where TYPE_SET is (LOWER_CASE, UPPER_CASE).

Well, consider an enumeration type
  type COLORS is (red, blue, green);
and an instance 
  package COLOR_IO is new TEXT_IO.ENUMERATION_IO(ENUM => COLORS);
and a variable
  C : COLORS := blue;
and an output operation
  COLOR_IO.PUT(ITEM => C);

All is well so far, everything compiles and runs except that the output
value is BLUE, because the default is Upper_Case. Now change the output
operation to
  COLOR_IO.PUT(ITEM => C, SET => LOWER_CASE);

Irvine Ada (HP835), IntegrAda (IBM-PC), VADS (Sun3) and AdaVantage (Sun3)
ALL bail out on a "LOWER_CASE is an undefined identifier" diagnostic.
Clearly something is going on here. According to LRM 14.3.9 this should be
allowed. Can anyone provide some enlightenment here?

I will post a program if anyone wants to try this out.
---------------------------------------------------------------------------
Prof. Michael Feldman
Department of Electrical Engineering and Computer Science
The George Washington University
Washington, DC 20052
+1-202-994-5253
mfeldman@seas.gwu.edu
---------------------------------------------------------------------------

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

* Re: Enumeration_IO
  1990-05-08  0:41 Enumeration_IO Mike Feldman
@ 1990-05-08 16:38 ` Alex Blakemore
  1990-05-08 18:32   ` Enumeration_IO Mike Feldman
  1990-05-08 23:53 ` Enumeration_IO M Y Ben Gershon
  1 sibling, 1 reply; 11+ messages in thread
From: Alex Blakemore @ 1990-05-08 16:38 UTC (permalink / raw)


In article <1846@sparko.gwu.edu> mfeldman@seas.gwu.edu (Mike Feldman) writes:
> In preparing some programs for a book I am working on ...
> Can anyone provide some enlightenment here?

  You forgot to specify the complete name of the enumeration literal.
  They are only directly visible where the type is directly visible.

  Change
    > COLOR_IO.PUT(ITEM => C, SET => LOWER_CASE);
  to
      COLOR_IO.PUT(ITEM => C, SET => TEXT_IO.LOWER_CASE);
                                     ^^^^^^^^
P.S. You're not going to use all caps for everything in your book are you?
     Too many people think Ada requires LONG_NAMES_WITH_ALL_CAPS_FOR_EVERYTHING

-----------------------------------------------------------------------
Alex Blakemore                       Internet: blakemore@software.org
Software Productivity Consortium     UUNET:    ...!uunet!software!blakemore
2214 Rock Hill Rd, Herndon VA 22070  Bellnet:  (703) 742-7125

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

* Re: Enumeration_IO
@ 1990-05-08 17:54 dritz
  0 siblings, 0 replies; 11+ messages in thread
From: dritz @ 1990-05-08 17:54 UTC (permalink / raw)


Having seen Michael Feldman's test program for Enumeration_IO, I think I can
say what the problem is.  The type Type_Set and its enumeration literals
Lower_Case and Upper_Case are declared in Text_IO, not in
Text_IO.Enumeration_IO.  The test program only "with"ed Text_IO; it did not
"use" it.  Hence the enumeration literal Lower_Case is not directly visible.
I would expect that adding "use Text_IO;" or replacing "Lower_Case" by
"Text_IO.Lower_Case" would solve the problem.

Ken Dritz
dritz@mcs.anl.gov

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

* Re: Enumeration_IO
  1990-05-08 16:38 ` Enumeration_IO Alex Blakemore
@ 1990-05-08 18:32   ` Mike Feldman
  1990-05-09 22:36     ` Enumeration_IO M Y Ben Gershon
  0 siblings, 1 reply; 11+ messages in thread
From: Mike Feldman @ 1990-05-08 18:32 UTC (permalink / raw)


In article <1117@software.software.org> blakemor@software.org (Alex Blakemore) writes:
>In article <1846@sparko.gwu.edu> mfeldman@seas.gwu.edu (Mike Feldman) writes:
>
>  You forgot to specify the complete name of the enumeration literal.
>  They are only directly visible where the type is directly visible.
Right. And thanks to the 2 dozen or so folks who pointed this out by e-mail.
I really like getting these notes from Ada folks I've not met before.
 
>  Change
>    > COLOR_IO.PUT(ITEM => C, SET => LOWER_CASE);
>  to
>      COLOR_IO.PUT(ITEM => C, SET => TEXT_IO.LOWER_CASE);
>                                     ^^^^^^^^
Indeed. After eight years of developing Ada code for all kinds of things,
but especially classroom projects and examples, I am going over all my code
and converting to eliminate unnecessary "use" clauses. It's taken me a long
time to buy in to the "avoid the USE" philosophy, but - with some exceptions
- I agree. So now I'm tripping over all the little pebbles associated with
ripping out the "use"s. It's a good exercise. I recommend it. Good for the soul.

>P.S. You're not going to use all caps for everything in your book are you?
>     Too many people think Ada requires LONG_NAMES_WITH_ALL_CAPS_FOR_EVERYTHING
No, I'm not. I'm using a basic style similar to that in Cohen's book. 
(Reserved words in upper case, all else in mixed case, reasonable lengths)
The book is for CS1 students just learning to program. Those kids really
benefit from seeing the reserved words in upper case, because it really
highlights the structural templates used and re-used in programs.
(There is controversy about this; an author needs to make a decision and
stick to it consistently, especially when teaching freshmen...)

Other things Ada can offer freshmen, aside from the obvious stuff like
packages, generics, and the like:

1. Named association of parameters. Kids have trouble matching formals to
   actuals, in any language. The FORMAL => ACTUAL binding that comes so
   naturally with named association really makes learning programming easier!

2. Consistent treatment of enumeration types, especially Enumeration_IO.
   There are freshman books that devote nearly a whole chapter to showing
   how to _write_ Enumeration_IO in Pascal, just to read and write booleans.
   String <-> numeric conversions are also good for the soul, but it's an
   "advanced topic" in the freshman context. Enumeration_IO makes it easy
   to treat enumerations as full members of the scalar-type community, so
   we can encourage their use.

I'll quit here, lest you think I'm pushing a book. I'll be glad to discuss
teaching philosophy by private e-mail. My bottom line is that it's not only
important to teach Ada to college students because it's good for Ada and
industry. It's important because Ada has a _lot_ to contribute to computer
science.
---------------------------------------------------------------------------
Prof. Michael Feldman
Department of Electrical Engineering and Computer Science
The George Washington University
Washington, DC 20052
+1-202-994-5253
mfeldman@seas.gwu.edu
---------------------------------------------------------------------------

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

* Re: Enumeration_IO
  1990-05-08  0:41 Enumeration_IO Mike Feldman
  1990-05-08 16:38 ` Enumeration_IO Alex Blakemore
@ 1990-05-08 23:53 ` M Y Ben Gershon
  1 sibling, 0 replies; 11+ messages in thread
From: M Y Ben Gershon @ 1990-05-08 23:53 UTC (permalink / raw)


Newsgroups: comp.lang.ada
Subject: Re: Enumeration_IO
Summary: 
Expires: 
References: <1846@sparko.gwu.edu>
Sender: 
Reply-To: umace03@doc.ic.ac.uk (M Y Ben Gershon)
Followup-To: 
Distribution: 
Organization: Imperial College Department of Computing
Keywords: 

In article <1846@sparko.gwu.edu> mfeldman@seas.gwu.edu (Mike Feldman) writes:
>In preparing some programs for a book I am working on, I have gotten
>interested in the idiosyncracies of Enumeration_IO. Specifically, the
>PUT operations in this generic package are supposed to have a parameter
>SET of type TYPE_SET, where TYPE_SET is (LOWER_CASE, UPPER_CASE).
>
>Well, consider an enumeration type
>  type COLORS is (red, blue, green);
>and an instance 
>  package COLOR_IO is new TEXT_IO.ENUMERATION_IO(ENUM => COLORS);
>and a variable
>  C : COLORS := blue;
>and an output operation
>  COLOR_IO.PUT(ITEM => C);
>
>All is well so far, everything compiles and runs except that the output
>value is BLUE, because the default is Upper_Case. Now change the output
>operation to
>  COLOR_IO.PUT(ITEM => C, SET => LOWER_CASE);
>
>Irvine Ada (HP835), IntegrAda (IBM-PC), VADS (Sun3) and AdaVantage (Sun3)
>ALL bail out on a "LOWER_CASE is an undefined identifier" diagnostic.
>Clearly something is going on here. According to LRM 14.3.9 this should be
>allowed. Can anyone provide some enlightenment here?



I can't claim to be an Ada expert, but altering it to the following:

  Color_IO.Put (Item => C, Set => Text_IO.Lower_Case);

seems to work fine in AdaStudent.  Alternatively, you could leave it unchanged
and have a 'use Text_IO' at the top, after 'with Text_IO'.  However, it
doesn't quite seem to make sense, and if the following is tried:

  Color_IO.Put (Item => C, Set => Color_IO.Lower_Case);

it doesn't work (as in the original example).  Why this should be I cannot
imagine, but when someone can explain it to us on the net, I'm sure we'll all
have learned something about generic packages that we didn't know before.

Michael Ben-Gershon
umace03@doc.ic.ac.uk

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

* Re: Enumeration_IO
  1990-05-08 18:32   ` Enumeration_IO Mike Feldman
@ 1990-05-09 22:36     ` M Y Ben Gershon
  1990-05-10  3:01       ` Enumeration_IO Mike Feldman
  0 siblings, 1 reply; 11+ messages in thread
From: M Y Ben Gershon @ 1990-05-09 22:36 UTC (permalink / raw)



>In article <1850@sparko.gwu.edu> mfeldman@seas.gwu.edu (Mike Feldman) writes:

>  Change
>    > COLOR_IO.PUT(ITEM => C, SET => LOWER_CASE);
>  to
>      COLOR_IO.PUT(ITEM => C, SET => TEXT_IO.LOWER_CASE);
>                                     ^^^^^^^^

Yes, OK.  But why doesn't COLOR_IO.LOWER_CASE work, seeing that we are using

package COLOR_IO is new TEXT_IO.ENUMERATION_IO(ENUM => COLORS);

shouldn't it follow that LOWER_CASE is distinct for each separate instantiation
of TEXT_IO.<enum_type> ?  Yet, if I put COLOR_IO.LOWER_CASE it doesn't work,
giving the same error message as before.

Michael Ben-Gershon
umace03@doc.ic.ac.uk

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

* Re: Enumeration_IO
  1990-05-09 22:36     ` Enumeration_IO M Y Ben Gershon
@ 1990-05-10  3:01       ` Mike Feldman
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Feldman @ 1990-05-10  3:01 UTC (permalink / raw)


In article <1874@gould.doc.ic.ac.uk> umace03@doc.ic.ac.uk (M Y Ben Gershon) writes:
>
>>In article <1850@sparko.gwu.edu> mfeldman@seas.gwu.edu (Mike Feldman) writes:
>
>>      COLOR_IO.PUT(ITEM => C, SET => TEXT_IO.LOWER_CASE);
>>                                     ^^^^^^^^
>
>Yes, OK.  But why doesn't COLOR_IO.LOWER_CASE work, seeing that we are using
>
>package COLOR_IO is new TEXT_IO.ENUMERATION_IO(ENUM => COLORS);
>
>shouldn't it follow that LOWER_CASE is distinct for each separate instantiation
>of TEXT_IO.<enum_type> ?  Yet, if I put COLOR_IO.LOWER_CASE it doesn't work,
>giving the same error message as before.

Well, now that I'm such an expert, this one is easy. It's because the
enumeration type TYPE_SET (which contains the literals UPPER_CASE and
LOWER_CASE) is exported from TEXT_IO (i.e. the outer layer) and NOT from
any of the enclosed generic packages. Checking the LRM or a good text's
appendix for the full spec of TEXT_IO will confirm this. So there's really
only one set of literals, and it ain't exported from COLOR_IO!

---------------------------------------------------------------------------
Prof. Michael Feldman
Department of Electrical Engineering and Computer Science
The George Washington University
Washington, DC 20052
+1-202-994-5253
mfeldman@seas.gwu.edu
---------------------------------------------------------------------------

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

* Enumeration_IO
@ 2000-04-06  0:00 NANCY HEHIR
  2000-04-07  0:00 ` Enumeration_IO Jeff Carter
  0 siblings, 1 reply; 11+ messages in thread
From: NANCY HEHIR @ 2000-04-06  0:00 UTC (permalink / raw)


Can anyone tell what the generic Enumeration_IO file in GNAT 3.12 should be
called ?
I can't seem to find it in my adainclude folder.






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

* Re: Enumeration_IO
  2000-04-06  0:00 Enumeration_IO NANCY HEHIR
@ 2000-04-07  0:00 ` Jeff Carter
  2000-04-07  0:00   ` Enumeration_IO Robert Dewar
  0 siblings, 1 reply; 11+ messages in thread
From: Jeff Carter @ 2000-04-07  0:00 UTC (permalink / raw)


Enumeration_IO is in Ada.Text_IO; look for a-textio.ad?
-- 
Jeff Carter
"We burst our pimples at you."
Monty Python & the Holy Grail




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

* Re: Enumeration_IO
  2000-04-07  0:00 ` Enumeration_IO Jeff Carter
@ 2000-04-07  0:00   ` Robert Dewar
  2000-04-08  0:00     ` Enumeration_IO Jeff Carter
  0 siblings, 1 reply; 11+ messages in thread
From: Robert Dewar @ 2000-04-07  0:00 UTC (permalink / raw)


In article <38ED2AC4.A7B9147B@acm.org>,
  jrcarter@acm.org wrote:

> Enumeration_IO is in Ada.Text_IO;

Yes, that's right

> look for a-textio.ad?

But that interestingly is wrong, internally GNAT handles
Enumeration_IO as a child unit. This has the advantage that
it is only loaded if needed.

Of course if Ada 95 had been designed from scratch then of
course Enumeration_IO would be a child unit, but we had to
be compatible with Ada 83, so we could not do this.

GNAT has some interesting internal circuits to implement
these subpackages of Text_IO as child packages, while preserving
the unfortunate subpackage semantics of the Ada 83 (and hence
Ada 95) definitions.

So the file to look in for this stuff is

a-tienio.ad? (Ada.Text_IO.Enumeration_IO)

Examine the compiler sources for more information on the
internal handling of this interesting transformation.


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: Enumeration_IO
  2000-04-07  0:00   ` Enumeration_IO Robert Dewar
@ 2000-04-08  0:00     ` Jeff Carter
  0 siblings, 0 replies; 11+ messages in thread
From: Jeff Carter @ 2000-04-08  0:00 UTC (permalink / raw)


Robert Dewar wrote:
> 
> In article <38ED2AC4.A7B9147B@acm.org>,
>   jrcarter@acm.org wrote:
> 
> > Enumeration_IO is in Ada.Text_IO;
> 
> Yes, that's right
> 
> > look for a-textio.ad?
> 
> But that interestingly is wrong, internally GNAT handles
> Enumeration_IO as a child unit. This has the advantage that
> it is only loaded if needed.

Interesting. What does it mean to "load" a generic if it is not
instantiated? 

-- 
Jeff Carter
"Son of a silly person."
Monty Python & the Holy Grail




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

end of thread, other threads:[~2000-04-08  0:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-06  0:00 Enumeration_IO NANCY HEHIR
2000-04-07  0:00 ` Enumeration_IO Jeff Carter
2000-04-07  0:00   ` Enumeration_IO Robert Dewar
2000-04-08  0:00     ` Enumeration_IO Jeff Carter
  -- strict thread matches above, loose matches on Subject: below --
1990-05-08 17:54 Enumeration_IO dritz
1990-05-08  0:41 Enumeration_IO Mike Feldman
1990-05-08 16:38 ` Enumeration_IO Alex Blakemore
1990-05-08 18:32   ` Enumeration_IO Mike Feldman
1990-05-09 22:36     ` Enumeration_IO M Y Ben Gershon
1990-05-10  3:01       ` Enumeration_IO Mike Feldman
1990-05-08 23:53 ` Enumeration_IO M Y Ben Gershon

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