comp.lang.ada
 help / color / mirror / Atom feed
* Visibility and Elaboration
@ 2003-06-09 10:47 And838N
  0 siblings, 0 replies; 9+ messages in thread
From: And838N @ 2003-06-09 10:47 UTC (permalink / raw)
  To: comp.lang.ada

David C. Hoos, Sr. wrote:
>If you look at your original post (on June 4), there was no "put_line"
>statement -- hence, the reason for my question
Ok, your right, there was no put_line statement.  There was only the
"put" statement.  The compiler would still have complained.

>GNAT did _not_ tell you it didn't know which one to use.
Ok, that must be why I wrote "Thus, GNAT's compiler message tells me 
not that GNAT can't determine which count to use but that I need to 
specify, for future readers, which count I needed."

>Using the GNAT compiler, the object file resulting from the
>compilation of your package would contain a procedure named 
>my_pkg___elabs. That procedure contains the elaboration code for your 
>package specification.
Cool!  I'm going to check that out.  Thank you.

>Elaboration is nothing at all like the instantiation of a C++ class.
Ok, elaboration is like the "preparation" of something declared static 
in C++ or Java? So your saying that all the elaborations in the 
following code happen before the main procedure is called?

with
ada.text_io,
ada.integer_text_io;

use
ada.text_io,
ada.integer_text_io;

procedure newelaboration is

    procedure doelaboration(i: integer) is
        package elo is
            value: Integer;
            procedure printvalue;
        end elo;

        package body elo is
            procedure printvalue is
            begin
                put(value);
            end printvalue;
        end elo;
    
    begin
        if i < 10 then
            elo.value := i;
            doelaboration(i+1);
            elo.printvalue;
        end if;
    end doelaboration;

begin

doelaboration(1);

end newelaboration;

So using the "new" reserved word is different than an elaboration?

Thanks for the help!

Andrew


__________________________________________________________________
McAfee VirusScan Online from the Netscape Network.
Comprehensive protection for your entire computer. Get your free trial today!
http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397

Get AOL Instant Messenger 5.1 free of charge.  Download Now!
http://aim.aol.com/aimnew/Aim/register.adp?promo=380455



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

* Re: Visibility and Elaboration
       [not found] <7BD8CDF4.671052CE.0015D3EC@netscape.net>
@ 2003-06-09 11:35 ` David C. Hoos, Sr.
  2003-06-09 18:14   ` Robert I. Eachus
  0 siblings, 1 reply; 9+ messages in thread
From: David C. Hoos, Sr. @ 2003-06-09 11:35 UTC (permalink / raw)
  To: And838N, comp.lang.ada


----- Original Message ----- 
From: <And838N@netscape.net>
To: <comp.lang.ada@ada.eu.org>
Sent: June 09, 2003 5:47 AM
Subject: Visibility and Elaboration


> David C. Hoos, Sr. wrote:
> >If you look at your original post (on June 4), there was no "put_line"
> >statement -- hence, the reason for my question
> Ok, your right, there was no put_line statement.  There was only the
> "put" statement.  The compiler would still have complained.

The compiler did _not_ complain when the unneeded "with" of Ada.Text_IO
was removed.

> 
> >GNAT did _not_ tell you it didn't know which one to use.
> Ok, that must be why I wrote "Thus, GNAT's compiler message tells me 
> not that GNAT can't determine which count to use but that I need to 
> specify, for future readers, which count I needed."
> 
> >Using the GNAT compiler, the object file resulting from the
> >compilation of your package would contain a procedure named 
> >my_pkg___elabs. That procedure contains the elaboration code for your 
> >package specification.
> Cool!  I'm going to check that out.  Thank you.
> 
> >Elaboration is nothing at all like the instantiation of a C++ class.
> Ok, elaboration is like the "preparation" of something declared static 
> in C++ or Java? So your saying that all the elaborations in the 
> following code happen before the main procedure is called?
The only elaborations resulting from the following code are from the
Ada standard libraries, viz:
ada__exceptions_E
system__exception_table_E
ada__io_exceptions_E
system__exceptions_E
system__secondary_stack_E
ada__tags_E
ada__streams_E
system__soft_links_E
system__finalization_root_E
system__finalization_implementation_E
ada__finalization_E
ada__finalization__list_controller_E
system__file_control_block_E
system__file_io_E
ada__text_io_E
Yes, they are all performed before exection of the main program.

Build you main program with the command gnatmake -g newelaboration
and look at the file b~newelaboration.adb generated by that process.
> 
> with
> ada.text_io,
> ada.integer_text_io;
> 
> use
> ada.text_io,
> ada.integer_text_io;
> 
> procedure newelaboration is
> 
>     procedure doelaboration(i: integer) is
>         package elo is
>             value: Integer;
>             procedure printvalue;
>         end elo;
> 
>         package body elo is
>             procedure printvalue is
>             begin
>                 put(value);
>             end printvalue;
>         end elo;
>     
>     begin
>         if i < 10 then
>             elo.value := i;
>             doelaboration(i+1);
>             elo.printvalue;
>         end if;
>     end doelaboration;
> 
> begin
> 
> doelaboration(1);
> 
> end newelaboration;
> 
> So using the "new" reserved word is different than an elaboration?
Yes.
> 
> Thanks for the help!
> 
> Andrew
> 
> 
> __________________________________________________________________
> McAfee VirusScan Online from the Netscape Network.
> Comprehensive protection for your entire computer. Get your free trial today!
> http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397
> 
> Get AOL Instant Messenger 5.1 free of charge.  Download Now!
> http://aim.aol.com/aimnew/Aim/register.adp?promo=380455
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 
> 




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

* Re: Visibility and Elaboration
  2003-06-09 11:35 ` Visibility and Elaboration David C. Hoos, Sr.
@ 2003-06-09 18:14   ` Robert I. Eachus
  2003-06-09 18:29     ` tmoran
  0 siblings, 1 reply; 9+ messages in thread
From: Robert I. Eachus @ 2003-06-09 18:14 UTC (permalink / raw)


David C. Hoos, Sr. wrote:

>>So using the "new" reserved word is different than an elaboration?

> Yes.

Fine, as long as you remember that the object created by the allocator 
may contain things that require elaboration.  In the code posted, the 
package elo nested in the procedure doelaboration is elaborated 
everytime doelaboration is called.  (Of course, this is not normal Ada, 
where all packages tend to be library units, or children of library 
packages.  Tasks created by allocators are a more common case of 
elaboration after the main program starts execution.)






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

* Re: Visibility and Elaboration
  2003-06-09 18:14   ` Robert I. Eachus
@ 2003-06-09 18:29     ` tmoran
  2003-06-11  6:50       ` Robert I. Eachus
  0 siblings, 1 reply; 9+ messages in thread
From: tmoran @ 2003-06-09 18:29 UTC (permalink / raw)


> Tasks created by allocators are a more common case of
> elaboration after the main program starts execution.
   "we elaborate declarations and execute statements", Barnes,
"Programming in Ada 95".  Are you using the term in a different
(more restricted) way?



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

* Visibility and Elaboration
@ 2003-06-10  8:33 And838N
  0 siblings, 0 replies; 9+ messages in thread
From: And838N @ 2003-06-10  8:33 UTC (permalink / raw)
  To: comp.lang.ada

> David C. Hoos, Sr. wrote:
>The compiler did _not_ complain when the unneeded "with" of 
>Ada.Text_IO was removed.
Huh, that's interesting. �adagcc says that "put" is undefined and that
the is possibly a missing with of Text_IO, therefore, for me, it is
a necessity. �Let's move on.

In the b~newelaborations.adb file I don't see any mention of an
'Elab_<anything> for the elo package. �Regardless, I'm not real
concerned about that aspect. �My concern is learning what happens
differently in an elaboration verses what happens by using the "new"
reserved word. �If I define a package such as elo outside the
newelaboration procedure and "with" and "use" it then it is only 
elaborated once.

I can still create new elos by using the "new" reserved word. �My
question is how is this different? �The elo "objects" (I don't even 
know if they are objects) that were created using "new" should all have 
their own copy of the data (value) and the printvalue procedure (by 
some means) like the elaborations would have in the 
newelabroations doelaborations subprocedure.

The way it is now, each time the doelaborations subprocedure is called 
the elo package is elaborated (before the actual call) and, like using 
"new", each one has their own copy of value and printvalue. �Is the 
only difference their scope and lifetime? �

Andrew






__________________________________________________________________
McAfee VirusScan Online from the Netscape Network.
Comprehensive protection for your entire computer. Get your free trial today!
http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397

Get AOL Instant Messenger 5.1 free of charge.  Download Now!
http://aim.aol.com/aimnew/Aim/register.adp?promo=380455



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

* Re: Visibility and Elaboration
  2003-06-09 18:29     ` tmoran
@ 2003-06-11  6:50       ` Robert I. Eachus
  2003-06-11  7:49         ` tmoran
  0 siblings, 1 reply; 9+ messages in thread
From: Robert I. Eachus @ 2003-06-11  6:50 UTC (permalink / raw)


tmoran@acm.org wrote:
>>Tasks created by allocators are a more common case of
>>elaboration after the main program starts execution.
> 
>    "we elaborate declarations and execute statements", Barnes,
> "Programming in Ada 95".  Are you using the term in a different
> (more restricted) way?

Not at all.  Most things that require elaboration occur in library 
packages, so that the elaboration occurs before the main program 
executes.  (And some are in the declarative part of the main procedure, 
you can argue whether they come before or after the main program starts 
executing.)

But some declarations occur in declare blocks, or in the declarative 
part of a task or in one of several other areas where elaboration csn 
occur well after the main program starts executing.

The usual place I see people getting confused by this is in generics. 
Some things are elaborated when the generic declaration is elaborated, 
other elaborations occur when the generic body is elaborated.  Finally 
the generic instance itself is elaborated.  Technically all three of 
these can occur after the main program is elaborated.  The most common 
case is that the generic declaration and generic body are elaborated 
before the main program.  Often instances of generics are elaborated 
after the main program is running.

When I taught Ada, one of the classroom exercises was to study an 
example where some parameters for the generic instantiation were read in 
by the main program, in particular the range of an array subtype.






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

* Re: Visibility and Elaboration
  2003-06-11  6:50       ` Robert I. Eachus
@ 2003-06-11  7:49         ` tmoran
  2003-06-11 21:11           ` Robert I. Eachus
  0 siblings, 1 reply; 9+ messages in thread
From: tmoran @ 2003-06-11  7:49 UTC (permalink / raw)


> >    "we elaborate declarations and execute statements", Barnes,
> ...
> But some declarations occur in declare blocks, or in the declarative
> part of a task or in one of several other areas where elaboration csn
> occur well after the main program starts executing.
  I remain confused.  That sentence sounds like elaboration after the main
program starts, is at least mildly unusual.  But my understanding is that
  procedure p(n:in positive) is
    x : array(1 .. n) of integer;
causes the "elaboration" of "x" each time "p" is called, ie, executing
a program is typically a constant back and forth between elaborating
declarations and executing statements.



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

* Visibility and Elaboration
@ 2003-06-11 10:40 And838N
  0 siblings, 0 replies; 9+ messages in thread
From: And838N @ 2003-06-11 10:40 UTC (permalink / raw)
  To: comp.lang.ada

David,

Ohhhhhhhhhhhhh...

Your talking about:

procedure x is
   astring: unbounded_string := "hello world";
   somenumber: integer := 0;
begin
   somenumber := count(astring, to_set(' '));
   put(somenumber);
end x;


When I am talking about:

procedure visibilitytest is
         astring: string := "hello world";
         somenumber: integer;
begin
         put_line(astring);
         somenumber := count(to_unbounded_string(astring), to_set(' 
'));
         put_line(Integer'image(somenumber));
end visibilitytest;


After I posted procedure x I added put_line(astring) instead of put
(somenumber) and reposted it.  I looked it up later and found procedure 
visibility test but not procedure x.  Anyway...
You have my sincere and public appologies for being rude and, with 
procedure x, I would not need ada.text_io.

Andrew




__________________________________________________________________
McAfee VirusScan Online from the Netscape Network.
Comprehensive protection for your entire computer. Get your free trial today!
http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397

Get AOL Instant Messenger 5.1 free of charge.  Download Now!
http://aim.aol.com/aimnew/Aim/register.adp?promo=380455



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

* Re: Visibility and Elaboration
  2003-06-11  7:49         ` tmoran
@ 2003-06-11 21:11           ` Robert I. Eachus
  0 siblings, 0 replies; 9+ messages in thread
From: Robert I. Eachus @ 2003-06-11 21:11 UTC (permalink / raw)


tmoran@acm.org wrote:

 >   I remain confused.  That sentence sounds like elaboration after the 
main
 > program starts, is at least mildly unusual.  But my understanding is that
 >   procedure p(n:in positive) is
 >     x : array(1 .. n) of integer;
 > causes the "elaboration" of "x" each time "p" is called, ie, executing
 > a program is typically a constant back and forth between elaborating
 > declarations and executing statements.

Not confused at all, it is a matter of viewpoint.  The "normal" Ada
programming style is to only use late elaborating objects when
necessary.  So maybe 90% of the object declarations in a "typical" Ada
program are elaborated either before or during the elaboration of the
main program.  However, if you count the number of times a particular
declaration is elaborated, early and/or static elaboration is often a
negligable part of the whole.

However the fact that almost all elaboration errors occur before the
main program runs encourages the view that elaboration checks all occur
before the program runs.  This is wrong, and is what I was originally
responding to.







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

end of thread, other threads:[~2003-06-11 21:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <7BD8CDF4.671052CE.0015D3EC@netscape.net>
2003-06-09 11:35 ` Visibility and Elaboration David C. Hoos, Sr.
2003-06-09 18:14   ` Robert I. Eachus
2003-06-09 18:29     ` tmoran
2003-06-11  6:50       ` Robert I. Eachus
2003-06-11  7:49         ` tmoran
2003-06-11 21:11           ` Robert I. Eachus
2003-06-11 10:40 And838N
  -- strict thread matches above, loose matches on Subject: below --
2003-06-10  8:33 And838N
2003-06-09 10:47 And838N

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