comp.lang.ada
 help / color / mirror / Atom feed
From: evans@evans.pgh.pa.us (Arthur Evans Jr)
Subject: Re: Please help a beginner! (second try)
Date: 1996/02/19
Date: 1996-02-19T00:00:00+00:00	[thread overview]
Message-ID: <evans-1902960823590001@ppp8.pgh.net> (raw)
In-Reply-To: 4g517q$438@helios.herts.ac.uk

In article <4g517q$438@helios.herts.ac.uk>, kst1ju@herts.ac.uk (Ryan) wrote:

> Could somebody please help me with what I am sure is a simple
> problem.
  [snip]
> 
> with TEXT_IO;
> package INT_IO is new TEXT_IO.INTEGER_IO(INTEGER);
> with INT_IO;
> 
> procedure proc1 is
> begin
>   TEXT_IO.PUT("Hello");
> -- fails ... "TEXT_IO not defined"
>   INT_IO.PUT(2);         
> -- accepted
> end proc1;
> 
> procedure main is
> begin
>   TEXT_IO.PUT("Hello");
> -- fails ... "TEXT_IO not defined"
>   INT_IO.PUT(2);         
> -- fails ... "INT_IO not defined"
> end main;

We are taught to use white space, including vertical spacing, to make
programs easier to read.  Here's an interesting example where the use of
white space has obscured what is actually happening.  An Ada compiler
interprets the above like this, where the only changes I have made are
to layout:

    --------------------------------------------

    -- 1st compliation unit
    with TEXT_IO;
    package INT_IO is new TEXT_IO.INTEGER_IO(INTEGER);

    --------------------------------------------

    -- 2nd compilation unit
    with INT_IO;
    procedure proc1 is
    begin
      TEXT_IO.PUT("Hello");
    -- fails ... "TEXT_IO not defined"
      INT_IO.PUT(2);         
    -- accepted
    end proc1;

    --------------------------------------------

    -- 3rd compilation unit
    procedure main is
    begin
      TEXT_IO.PUT("Hello");
    -- fails ... "TEXT_IO not defined"
      INT_IO.PUT(2);         
    -- fails ... "INT_IO not defined"
    end main;

Now it's clear that "with TEXT_IO" applies to only the instantiation of
TEXT_IO.INTEGER_IO and so TEXT_IO is not visible in the 2nd and 3rd
units.  Further, "WITH INT_IO" apllies to only the 2nd unit.  Add some
"with" clauses and all should be well.

Art Evans

Arthur Evans Jr, PhD        Phone: 412-963-0839
Ada Consulting              FAX:   412-963-0927
461 Fairview Road
Pittsburgh PA  15238-1933
evans@evans.pgh.pa.us




      parent reply	other threads:[~1996-02-19  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-02-17  0:00 Please help a beginner! (second try) Ryan
1996-02-17  0:00 ` smoneill
1996-02-17  0:00   ` Robert Dewar
1996-02-18  0:00 ` Steve Doiel
1996-02-18  0:00   ` Robert Dewar
1996-02-19  0:00 ` Arthur Evans Jr [this message]
replies disabled

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