comp.lang.ada
 help / color / mirror / Atom feed
* Initializers
@ 2006-12-20  2:02 markww
  2006-12-20  4:52 ` Initializers Larry Kilgallen
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: markww @ 2006-12-20  2:02 UTC (permalink / raw)


Hi everyone,

I'm trying to compare C++ to Ada. I'm looking specifically at Ada's
lack of 'initializers'. I am guessing that this means there is no
'constructor' to Ada packages maybe? If that's the case - where do you
initialize anything that needs setup when it comes into existence?

Thanks,
Mark




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

* Re: Initializers
  2006-12-20  2:02 Initializers markww
@ 2006-12-20  4:52 ` Larry Kilgallen
  2006-12-20  7:59   ` Initializers Jean-Pierre Rosen
  2006-12-20  6:57 ` Initializers Martin Krischik
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Larry Kilgallen @ 2006-12-20  4:52 UTC (permalink / raw)


In article <1166580131.054327.67090@80g2000cwy.googlegroups.com>, "markww" <markww@gmail.com> writes:

> I'm trying to compare C++ to Ada. I'm looking specifically at Ada's
> lack of 'initializers'. I am guessing that this means there is no
> 'constructor' to Ada packages maybe? If that's the case - where do you
> initialize anything that needs setup when it comes into existence?

For record components (the most common case I run into) take care of
it in the type declaration:

	FIELD_1 : INTEGER := 15;
	FIELD_2 : STRING ( 1 .. 5 ) := "Omaha";



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

* Re: Initializers
  2006-12-20  2:02 Initializers markww
  2006-12-20  4:52 ` Initializers Larry Kilgallen
@ 2006-12-20  6:57 ` Martin Krischik
  2006-12-20 10:35 ` Initializers Dmitry A. Kazakov
  2006-12-20 15:08 ` Initializers Georg Bauhaus
  3 siblings, 0 replies; 8+ messages in thread
From: Martin Krischik @ 2006-12-20  6:57 UTC (permalink / raw)


markww wrote:

> Hi everyone,
> 
> I'm trying to compare C++ to Ada. I'm looking specifically at Ada's
> lack of 'initializers'. I am guessing that this means there is no
> 'constructor' to Ada packages maybe? If that's the case - where do you
> initialize anything that needs setup when it comes into existence?

You should be aware that the language features are distributed differently
between namespaces/packages and classes/tagged-types in Ada/C++. Try
reading:

http://en.wikibooks.org/wiki/Ada_Programming/Object_Orientation
http://en.wikibooks.org/wiki/Ada_Programming/Packages

Mind you, the "Packages" chapter is missing the part for initialisation.
Larry allready told you how to perform simple package initialisation - for
more complex needs packages can have a body - just like a procedure.

For tagged type you might also want to check out the package
Ada.Finalisation - despise the name it also handles initialisation and copy
construction.

Martin

-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



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

* Re: Initializers
  2006-12-20  4:52 ` Initializers Larry Kilgallen
@ 2006-12-20  7:59   ` Jean-Pierre Rosen
  0 siblings, 0 replies; 8+ messages in thread
From: Jean-Pierre Rosen @ 2006-12-20  7:59 UTC (permalink / raw)


Larry Kilgallen a �crit :
> In article <1166580131.054327.67090@80g2000cwy.googlegroups.com>, "markww" <markww@gmail.com> writes:
> 
>> I'm trying to compare C++ to Ada. I'm looking specifically at Ada's
>> lack of 'initializers'. I am guessing that this means there is no
>> 'constructor' to Ada packages maybe? If that's the case - where do you
>> initialize anything that needs setup when it comes into existence?
> 
> For record components (the most common case I run into) take care of
> it in the type declaration:
> 
> 	FIELD_1 : INTEGER := 15;
> 	FIELD_2 : STRING ( 1 .. 5 ) := "Omaha";
.. And for packages, put a sequence of statement in the body of the package:

package body Blah is
   -- Declarations
begin
   -- do any initialization here
end Blah;

-- 
---------------------------------------------------------
            J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



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

* Re: Initializers
  2006-12-20  2:02 Initializers markww
  2006-12-20  4:52 ` Initializers Larry Kilgallen
  2006-12-20  6:57 ` Initializers Martin Krischik
@ 2006-12-20 10:35 ` Dmitry A. Kazakov
  2006-12-20 15:08 ` Initializers Georg Bauhaus
  3 siblings, 0 replies; 8+ messages in thread
From: Dmitry A. Kazakov @ 2006-12-20 10:35 UTC (permalink / raw)


On 19 Dec 2006 18:02:11 -0800, markww wrote:

> I'm trying to compare C++ to Ada. I'm looking specifically at Ada's
> lack of 'initializers'. I am guessing that this means there is no
> 'constructor' to Ada packages maybe? If that's the case - where do you
> initialize anything that needs setup when it comes into existence?

They exist, the things they do Ada reference manual calls "package
elaboration." You can attach your code to elaboration in many ways. Begin
in the package body was already mentioned. Then of course all initialized
objects declared in the package are initialized during elaboration. For
example, constants take values, tasks start, controlled objects get their
Initialize called etc. 

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Initializers
  2006-12-20  2:02 Initializers markww
                   ` (2 preceding siblings ...)
  2006-12-20 10:35 ` Initializers Dmitry A. Kazakov
@ 2006-12-20 15:08 ` Georg Bauhaus
  2006-12-20 20:59   ` Initializers markww
  3 siblings, 1 reply; 8+ messages in thread
From: Georg Bauhaus @ 2006-12-20 15:08 UTC (permalink / raw)


On Tue, 2006-12-19 at 18:02 -0800, markww wrote:
> Hi everyone,
> 
> I'm trying to compare C++ to Ada. I'm looking specifically at Ada's
> lack of 'initializers'. I am guessing that this means there is no
> 'constructor' to Ada packages maybe?

Others have given examples of initialization of record components
and of package initialization blocks. (Two different things.)
Another 2c:

There are also construction subprograms and nested Factory packages
that are commonly used for initializing objects. Some of this is
explained in the Ada wikibook, and in many Ada text books.

In addition, consider:

- types whose objects must not be initialised, not even default
  initialized. A reason might be that their bits are mapped
  to hardware. Initialization would mean sending signals to the
  hardware. You don't want some signals sent only because the
  language uses some default initialization. So in Ada, you can
  turn initialization off, entirely.

- limited types. For every object of a limited record you can
  obtain its access within the record definition. This allows
  one or more construction functions invoked automatically
  when an object is created but not initialized "by hand":

  package P is

    type L is limited private;

    package Factory is

      function make(item: access L) return Natural;

    end Factory;

  private

    type L is limited record
      hook: Natural := Factory.make(L'access);
      stuff: Integer;
    end record;

  end P;

  Factory.make has access to all the components of its Item
  parameter, including Stuff. It is invoked automatically
  for an object of type L that isn't explicitly initialized.

- discriminated types. These will force partial initialization
  because the discriminant needs to have a value to make the
  object be of some specific type, and have a known size etc.
  There are some tricks here.

- nested scope. This is useful if you compare initialization in
  C++ and Ada because nesting is built into Ada and can be used
  here. Support for nested scopes (dynamic + static) is limited
  in C++ by comparison I think. There are cases where
  you would pass parameters to a C++ constructor, where in Ada
  you needn't pass them because they are in (local) scope.


 -- Georg






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

* Re: Initializers
  2006-12-20 15:08 ` Initializers Georg Bauhaus
@ 2006-12-20 20:59   ` markww
  2006-12-21  5:14     ` AW: Initializers Grein, Christoph (Fa. ESG)
  0 siblings, 1 reply; 8+ messages in thread
From: markww @ 2006-12-20 20:59 UTC (permalink / raw)



Georg Bauhaus wrote:
> On Tue, 2006-12-19 at 18:02 -0800, markww wrote:
> > Hi everyone,
> >
> > I'm trying to compare C++ to Ada. I'm looking specifically at Ada's
> > lack of 'initializers'. I am guessing that this means there is no
> > 'constructor' to Ada packages maybe?
>
> Others have given examples of initialization of record components
> and of package initialization blocks. (Two different things.)
> Another 2c:
>
> There are also construction subprograms and nested Factory packages
> that are commonly used for initializing objects. Some of this is
> explained in the Ada wikibook, and in many Ada text books.
>
> In addition, consider:
>
> - types whose objects must not be initialised, not even default
>   initialized. A reason might be that their bits are mapped
>   to hardware. Initialization would mean sending signals to the
>   hardware. You don't want some signals sent only because the
>   language uses some default initialization. So in Ada, you can
>   turn initialization off, entirely.
>
> - limited types. For every object of a limited record you can
>   obtain its access within the record definition. This allows
>   one or more construction functions invoked automatically
>   when an object is created but not initialized "by hand":
>
>   package P is
>
>     type L is limited private;
>
>     package Factory is
>
>       function make(item: access L) return Natural;
>
>     end Factory;
>
>   private
>
>     type L is limited record
>       hook: Natural := Factory.make(L'access);
>       stuff: Integer;
>     end record;
>
>   end P;
>
>   Factory.make has access to all the components of its Item
>   parameter, including Stuff. It is invoked automatically
>   for an object of type L that isn't explicitly initialized.
>
> - discriminated types. These will force partial initialization
>   because the discriminant needs to have a value to make the
>   object be of some specific type, and have a known size etc.
>   There are some tricks here.
>
> - nested scope. This is useful if you compare initialization in
>   C++ and Ada because nesting is built into Ada and can be used
>   here. Support for nested scopes (dynamic + static) is limited
>   in C++ by comparison I think. There are cases where
>   you would pass parameters to a C++ constructor, where in Ada
>   you needn't pass them because they are in (local) scope.
>
>
>  -- Georg

Ok thanks for your replies. I also found this on 'elaboration':

    http://www.adapower.com/rm95/RM-7-6.html

where do you guys find examples of how to use these packages?

Thanks,
Mark




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

* AW: Initializers
  2006-12-20 20:59   ` Initializers markww
@ 2006-12-21  5:14     ` Grein, Christoph (Fa. ESG)
  0 siblings, 0 replies; 8+ messages in thread
From: Grein, Christoph (Fa. ESG) @ 2006-12-21  5:14 UTC (permalink / raw)
  To: comp.lang.ada

 
>    http://www.adapower.com/rm95/RM-7-6.html
>
> where do you guys find examples of how to use these packages?

http://www.christ-usch-grein.homepage.t-online.de/AdaMagica/Secretive.ht
ml



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

end of thread, other threads:[~2006-12-21  5:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-20  2:02 Initializers markww
2006-12-20  4:52 ` Initializers Larry Kilgallen
2006-12-20  7:59   ` Initializers Jean-Pierre Rosen
2006-12-20  6:57 ` Initializers Martin Krischik
2006-12-20 10:35 ` Initializers Dmitry A. Kazakov
2006-12-20 15:08 ` Initializers Georg Bauhaus
2006-12-20 20:59   ` Initializers markww
2006-12-21  5:14     ` AW: Initializers Grein, Christoph (Fa. ESG)

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