* Re: Global scope for instantiated generic package?
2010-08-30 13:12 Global scope for instantiated generic package? Trogdor
@ 2010-08-30 13:25 ` Jacob Sparre Andersen
2010-08-30 13:28 ` Georg Bauhaus
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Jacob Sparre Andersen @ 2010-08-30 13:25 UTC (permalink / raw)
Trogdor wrote:
> type BigInt is range 1..10_000_000_000_000;
This has to be done in a declarative region (i.e. inside a package or
subprogram). This could be in a completely independent package:
-- trogdor.ads (for GNAT)
package Trogdor is
type Integer is range 1..10_000_000_000_000;
end Trogdor;
> I then wish to get and put these values, so I instantiate
> Integer_IO.
>
> package BigInt_IO is new integer_IO(BigInt);
This can be a complation unit of its own:
-- trogdor_io.ads (for GNAT)
with Trogdor;
package Trogdor_IO is new Ada.Text_IO.Integer_IO (Trogdor.Integer);
Or you can put it inside the same package as the number type:
-- trogdor.ads (for GNAT)
package Trogdor is
type Integer is range 1..10_000_000_000_000;
package IO is new Ada.Text_IO.Integer_IO (Integer);
end Trogdor;
> My program consists of three parts: the main body, a package spec
> and a package body (the package containing all the subprograms and
> functions).
>
> 1) Is this the way to do it, or is there a preffered way?
If the subprograms are specific to the program, you may want to declare
them in the declarative part of the program rather than in a separate
package.
Kind regards,
Jacob Sparre Andersen
--
Jacob Sparre Andersen Research & Innovation
Vesterbrogade 148K, 1. th.
1620 K�benhavn V
Danmark
Phone: +45 21 49 08 04
E-mail: jacob@jacob-sparre.dk
Web-site: http://www.jacob-sparre.dk/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Global scope for instantiated generic package?
2010-08-30 13:12 Global scope for instantiated generic package? Trogdor
2010-08-30 13:25 ` Jacob Sparre Andersen
@ 2010-08-30 13:28 ` Georg Bauhaus
2010-08-30 13:30 ` Ludovic Brenta
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Georg Bauhaus @ 2010-08-30 13:28 UTC (permalink / raw)
On 30.08.10 15:12, Trogdor wrote:
> 2) Where, speciffically, do I place the above two lines (and the
> associated "with" line) so that I can BigInt_io.get from the main
> body and the package subprograms as well?
One way to place the declarations is in a common package.
with Ada.Text_IO; use Ada.Text_IO;
package Big_Stuff is
type BigInt is range 1..10_000_000_000_000;
-- ... BigInt subprograms
package BigInt_IO is new integer_IO(BigInt);
end Big_Stuff;
A main unit can then with package Big_Stuff (and "use"
it); the procedure bodies in Big_Stuff's body will see
BigInt_IO, too.
Georg
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Global scope for instantiated generic package?
2010-08-30 13:12 Global scope for instantiated generic package? Trogdor
2010-08-30 13:25 ` Jacob Sparre Andersen
2010-08-30 13:28 ` Georg Bauhaus
@ 2010-08-30 13:30 ` Ludovic Brenta
2010-08-30 13:47 ` Dmitry A. Kazakov
2010-08-30 18:49 ` Jeffrey Carter
4 siblings, 0 replies; 6+ messages in thread
From: Ludovic Brenta @ 2010-08-30 13:30 UTC (permalink / raw)
Trogdor wrote on comp.lang.ada:
> I wish to manipulate very large integers with values in the
> trillions. This would require a 64 bit integer type, so to maintain
> portability I specify a new type using range and let the compiler do
> the right thing.
>
> type BigInt is range 1..10_000_000_000_000;
>
> I then wish to get and put these values, so I instantiate
> Integer_IO.
>
> package BigInt_IO is new integer_IO(BigInt);
>
> My program consists of three parts: the main body, a package spec
> and a package body (the package containing all the subprograms and
> functions).
>
> 1) Is this the way to do it, or is there a preffered way?
>
> 2) Where, speciffically, do I place the above two lines (and the
> associated "with" line) so that I can BigInt_io.get from the main
> body and the package subprograms as well?
>
> So far, every place I have tried has offended the compiler. And my
> text books have been of little help (I have more on order).
>
> Thanks for the help!
Without at least a sekeleton of your sources I'm not sure I understand
your question, so for clarity I'll assume you currently have:
with Ada.Text_IO;
package P is
type BigInt is range 1..10_000_000_000_000;
package BigInt_IO is new Ada.Text_IO.Integer_IO (BigInt);
procedure Proc (X : out BigInt);
end P;
package body P is
procedure Proc (X : out BigInt) is
begin
BigInt_IO.Get (X); -- OK
end Proc;
end P;
with P;
procedure Main is
X : BigInt;
begin
P.Proc (X); -- OK
BigInt_IO.Get (X); -- error, BigInt_IO not directly visible
P.BigInt_IO.Get (X); -- OK
end Main;
You can resolve the error in two ways:
1) add a "use P;" clause in procedure Main
2) Declare BigInt_IO at library level, like so:
-- bigint_io.ads
with Ada.Text_IO;
with P;
package BigInt_IO is new Ada.Text_IO.Integer_IO (P.BigInt);
and then add "with BigInt_IO" clauses in both the body of P and the
body of Main.
HTH
--
Ludovic Brenta.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Global scope for instantiated generic package?
2010-08-30 13:12 Global scope for instantiated generic package? Trogdor
` (2 preceding siblings ...)
2010-08-30 13:30 ` Ludovic Brenta
@ 2010-08-30 13:47 ` Dmitry A. Kazakov
2010-08-30 18:49 ` Jeffrey Carter
4 siblings, 0 replies; 6+ messages in thread
From: Dmitry A. Kazakov @ 2010-08-30 13:47 UTC (permalink / raw)
On Mon, 30 Aug 2010 08:12:19 -0500, Trogdor wrote:
> I wish to manipulate very large integers with values in the
> trillions. This would require a 64 bit integer type, so to maintain
> portability I specify a new type using range and let the compiler do
> the right thing.
>
> type BigInt is range 1..10_000_000_000_000;
>
> I then wish to get and put these values, so I instantiate
> Integer_IO.
>
> package BigInt_IO is new integer_IO(BigInt);
>
> My program consists of three parts: the main body, a package spec
> and a package body (the package containing all the subprograms and
> functions).
>
> 1) Is this the way to do it, or is there a preffered way?
I usually do it this way:
package Big_Integers is
type Big_Integer is range 1..10_000_000_000_000;
end Big_Integers;
Further instantiations based on it go into children packages:
with Ada.Text_IO; use Ada.Text_IO;
package Big_Integers.IO is new Integer_IO (Big_Integer);
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Global scope for instantiated generic package?
2010-08-30 13:12 Global scope for instantiated generic package? Trogdor
` (3 preceding siblings ...)
2010-08-30 13:47 ` Dmitry A. Kazakov
@ 2010-08-30 18:49 ` Jeffrey Carter
4 siblings, 0 replies; 6+ messages in thread
From: Jeffrey Carter @ 2010-08-30 18:49 UTC (permalink / raw)
On 08/30/2010 06:12 AM, Trogdor wrote:
>
> 1) Is this the way to do it, or is there a preffered way?
This sounds reasonable, though I'd need to have more detail to decide if it's
the way I'd do it.
> 2) Where, speciffically, do I place the above two lines (and the
> associated "with" line) so that I can BigInt_io.get from the main
> body and the package subprograms as well?
These would go in the (visible part of) the package specification.
> So far, every place I have tried has offended the compiler. And my
> text books have been of little help (I have more on order).
It would help to know which compiler you're using, what you have tried, and how
it offended the compiler.
--
Jeff Carter
"How'd you like to hide the egg and gurgitate
a few saucers of mocha java?"
Never Give a Sucker an Even Break
101
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
^ permalink raw reply [flat|nested] 6+ messages in thread