comp.lang.ada
 help / color / mirror / Atom feed
* Re: Generic Packages
       [not found] <4inq3c$lr9@NNTP.MsState.Edu>
@ 1996-03-22  0:00 ` John Herro
  1996-03-22  0:00   ` Samuel Tardieu
  0 siblings, 1 reply; 25+ messages in thread
From: John Herro @ 1996-03-22  0:00 UTC (permalink / raw)


vkire@ERC.MsState.Edu (Kiril Nikola Vidimce) writes:
> ... I was wondering was if I could define a generic
> package with a generic constant/value that would
> be passed when instantiating the package.
     Inside a generic package, generic formal parameters are treated as
constants in any case.  The following example, which works in Ada 83 and
Ada 95, instantiates a generic package with a constant:

generic
   Number : Integer;
package P is
   procedure Show;
end P;

with Text_IO;
package body P is
   procedure Show is
   begin
      Text_IO.Put_Line(Integer'Image(Number));
   end Show;
end P;

with P;
procedure Test is
   I : constant Integer := 3;
   package P3 is new P(Number => I);
begin
   P3.Show;
end Test;

    As expected, the program displays 3, and if you attempt to add the
line
Number := Number + 1;
to procedure Show in the body of P, the compiler will reject the statement
as an assignment to a read-only object.  However, that's still true even
if you remove the word constant from the line
I : constant Integer := 3;
in procedure Test.  The generic formal parameter is treated as a constant
in any case.
     For this reason you can't declare
generic
   Number : constant Integer;
package P is ...

> I am very new in Ada ...
     You've come to the right place!  I hope this helps.  Good luck
learning and using Ada; you'll like it!
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor


 




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

* Re: Generic Packages
  1996-03-22  0:00 ` John Herro
@ 1996-03-22  0:00   ` Samuel Tardieu
  0 siblings, 0 replies; 25+ messages in thread
From: Samuel Tardieu @ 1996-03-22  0:00 UTC (permalink / raw)


>>>>> "John" == John Herro <johnherro@aol.com> writes:

John> generic formal parameter is treated as a constant in any
John> case. For this reason you can't declare
John> generic
John>   Number : constant Integer;
John> package P is ...

Mmm... I think you are wrong. The reason which prevents you from
modifying Number in your first example is that the "in" keyword is
ommitted. A generic formal may be either "in" or "in out" (of course,
not "out" only).

So you may do:

generic
  Number : in out Integer;
package G is
  procedure Increment;
end G;
package body G is
  procedure Increment is
  begin
     Number := Number + 1;
  end Increment;
end G;

with G;
with Text_IO; use Text_IO;
procedure T is
  I : Integer := 5;
  package P is new G (I);
begin
  Put_Line (Integer'Image(I));
  P.Increment;
  Put_Line (Integer'Image(I));
end T;

and it will print:

5
6

  Sam
--
"La cervelle des petits enfants, ca doit avoir comme un petit gout de noisette"
                                                       Charles Baudelaire




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

* Re: Generic Packages
       [not found] <5e03nm$esq@netty.york.ac.uk>
@ 1997-02-15  0:00 ` Jon S Anthony
  1997-02-20  0:00 ` phtruong
  1 sibling, 0 replies; 25+ messages in thread
From: Jon S Anthony @ 1997-02-15  0:00 UTC (permalink / raw)



In article <5e03nm$esq@netty.york.ac.uk> keh105@york.ac.uk (Quorlia) writes:

> I have a package header dll.ads and a package body dll.adb but I'm not
> sure how to compile them.  Gnatmake comes up with soem nasty messages
> about not finding units.  Do I need a uses clause somewhere?

Not enough information here to say anything...

/Jon
-- 
Jon Anthony
Organon Motives, Inc.
Belmont, MA 02178
617.484.3383
jsa@organon.com





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

* Re: Generic Packages
       [not found] <5e03nm$esq@netty.york.ac.uk>
  1997-02-15  0:00 ` Jon S Anthony
@ 1997-02-20  0:00 ` phtruong
  1997-02-21  0:00   ` Robert Dewar
  1 sibling, 1 reply; 25+ messages in thread
From: phtruong @ 1997-02-20  0:00 UTC (permalink / raw)



In article <5e03nm$esq@netty.york.ac.uk>, keh105@york.ac.uk (Quorlia) writes:
> I have a package header dll.ads and a package body dll.adb but I'm not
> sure how to compile them.  Gnatmake comes up with soem nasty messages
> about not finding units.  Do I need a uses clause somewhere?

  Yeah! you do need.  You have to include 'with generic_name' and
      package any_name generic_name(data_type, ...) is new
      use any_name

  In the program where you will use functions in the package.
  Also, don't foget to compile (not link) the package first.
  More questions? email me.




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

* Re: Generic Packages
  1997-02-20  0:00 ` phtruong
@ 1997-02-21  0:00   ` Robert Dewar
  1997-02-25  0:00     ` Quorlia
  0 siblings, 1 reply; 25+ messages in thread
From: Robert Dewar @ 1997-02-21  0:00 UTC (permalink / raw)



phtruong said

<<  In the program where you will use functions in the package.
  Also, don't foget to compile (not link) the package first.
  More questions? email me.>>

This advice is confusing, you just use gnatmake, and it will compile
and link what needs to be compiled and linked!





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

* Re: Generic Packages
  1997-02-21  0:00   ` Robert Dewar
@ 1997-02-25  0:00     ` Quorlia
  1997-02-27  0:00       ` Robert Dewar
  0 siblings, 1 reply; 25+ messages in thread
From: Quorlia @ 1997-02-25  0:00 UTC (permalink / raw)



Robert Dewar (dewar@merv.cs.nyu.edu) wrote:
: phtruong said

: <<  In the program where you will use functions in the package.
:   Also, don't foget to compile (not link) the package first.
:   More questions? email me.>>

: This advice is confusing, you just use gnatmake, and it will compile
: and link what needs to be compiled and linked!

Thanks - I'd managed to get the program and package on separate accounts
on separate computers (please don't ask how, I don't know) which rather
buggered gnatmake up when it looked for the prog!

 --
 ________________________________________________ _________________________
|                                                |                         |
|  Kirsty Hollingworth                           |  "Forgive my inability  |
|  keh105@york.ac.uk                             |   to communicate, but   |
|  http://www.york.ac.uk/~keh105/                |   there are things you  |
|  http://www.geocities.com/CapeCanaveral/8080/  |   may not understand."  |
|  http://www.plan9.cs.york.ac.uk/usr/keh105/    |   -- Count Iblis        |
|________________________________________________|_________________________|




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

* Re: Generic Packages
  1997-02-25  0:00     ` Quorlia
@ 1997-02-27  0:00       ` Robert Dewar
  0 siblings, 0 replies; 25+ messages in thread
From: Robert Dewar @ 1997-02-27  0:00 UTC (permalink / raw)



Kirsty said

<<Thanks - I'd managed to get the program and package on separate accounts
on separate computers (please don't ask how, I don't know) which rather
buggered gnatmake up when it looked for the prog!>>

note that gnatmake can perfectly well handle looking for sources in
various directories (across NFS mounts etc), by use of search paths
and/or -I switches. Of course gnatmake is NOT able to access files
that are inaccessible at the file system level (clearly fixing this
deficiency should go on our to-do list :) :-)





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

* Generic Packages
@ 1998-08-10  0:00 Tory Patnoe
  1998-08-11  0:00 ` Tucker Taft
                   ` (3 more replies)
  0 siblings, 4 replies; 25+ messages in thread
From: Tory Patnoe @ 1998-08-10  0:00 UTC (permalink / raw)


Here is a quick question which I was unable to find the answer to in the Ada95 Reference Manual.

I have a program which takes a long time to elaborate.  I am suspecting it has something to do with the generic integer_io.  The
current program (not my design!) looks something like this...

package process1 is
    yada-yada-yada;
    package int_io is new integer_io; use int_io;
end process1;

package process2 is
    more yada-yada-yada;
    package int_io is new integer_io; use int_io;
end process2;

Does the compiler make TWO separate instantiations of int_io in this case?   It would, therefore, make my code larger and take more
time at elaboration?  I suspect this is the case and consequently it would be better to do something like this.

package int_io is new integer_io; use int_io;

with int_io; use int_io;
package process1 is
    yada-yada-yada;
end process1;

with int_io; use int_io;
package process2 is
    more yada-yada-yada;
end process2;

Thanks

Tory




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

* Re: Generic Packages
  1998-08-10  0:00 Generic Packages Tory Patnoe
@ 1998-08-11  0:00 ` Tucker Taft
  1998-08-11  0:00 ` Robert I. Eachus
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 25+ messages in thread
From: Tucker Taft @ 1998-08-11  0:00 UTC (permalink / raw)


Tory Patnoe (tory.l.patnoe@lmco.com) wrote:

: Here is a quick question which I was unable to find the answer to in 
: the Ada95 Reference Manual.

: I have a program which takes a long time to elaborate.  I am suspecting 
: it has something to do with the generic integer_io.  The
: current program (not my design!) looks something like this...

: package process1 is
:     yada-yada-yada;
:     package int_io is new integer_io; use int_io;
: end process1;

: package process2 is
:     more yada-yada-yada;
:     package int_io is new integer_io; use int_io;
: end process2;

: Does the compiler make TWO separate instantiations of int_io in this case?   

Probably.

: ... It would, therefore, make my code larger 

Somewhat, though the Integer_IO put routines should not be
huge.  I would presume most of the logic is in out-of-line,
non-generic routines used by Integer'Image & 'Value as well.

: ... and take more time at elaboration?  

This seems very unlikely.  I can't imagine what the
elaboration of Integer_IO is doing other than setting a few
elaboration bits true.  Of course, your compiler might be
painstakingly building up some sort of parsing table at elaboration
time, but if so, probably time to start evaluating other vendors.

: I suspect this is the case and consequently it would be better to 
: do something like this.

: package int_io is new integer_io; use int_io;

: with int_io; use int_io;
: package process1 is
:     yada-yada-yada;
: end process1;

: with int_io; use int_io;
: package process2 is
:     more yada-yada-yada;
: end process2;

This is certainly preferable in general.  But I would be
very surprised if this explains any significant space or time
spent in elaboration.  Have you tried using any sort of
CPU-time profiling?

: Thanks

: Tory

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics/AverStar, Inc.  Burlington, MA  USA




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

* Re: Generic Packages
  1998-08-10  0:00 Generic Packages Tory Patnoe
  1998-08-11  0:00 ` Tucker Taft
@ 1998-08-11  0:00 ` Robert I. Eachus
  1998-08-12  0:00 ` Dale Stanbrough
  1998-08-17  0:00 ` Dr. Hubert B. Keller
  3 siblings, 0 replies; 25+ messages in thread
From: Robert I. Eachus @ 1998-08-11  0:00 UTC (permalink / raw)


In article <35CF1129.4DCB0B15@lmco.com> Tory Patnoe <tory.l.patnoe@lmco.com> writes:

> Does the compiler make TWO separate instantiations of int_io in this
> case?   It would, therefore, make my code larger and take more 
> time at elaboration?  I suspect this is the case and consequently it
> would be better to do something like this. 

>   package int_io is new integer_io; use int_io;

    Normally the overhead for elaborating a generic instantiation is
trivial, on the order of a procedure call and a few assignments.
However, it is worth noting that combining instances like this can
have semantic effects.  Integer_IO has two variables, Default_Base and
Default_Width that can be set by user, but hardly ever are.  (In fact
they probably account for two of those assignments during
instantiation.)
--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




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

* Re: Generic Packages
  1998-08-10  0:00 Generic Packages Tory Patnoe
  1998-08-11  0:00 ` Tucker Taft
  1998-08-11  0:00 ` Robert I. Eachus
@ 1998-08-12  0:00 ` Dale Stanbrough
  1998-08-17  0:00 ` Dr. Hubert B. Keller
  3 siblings, 0 replies; 25+ messages in thread
From: Dale Stanbrough @ 1998-08-12  0:00 UTC (permalink / raw)


Whether the compiler makes two copies of an instantiated package depends, of
course, on the compiler.

Most compilers do not share generics, so you end up with code bloat. 

This is why I follow the rule of thumb that most package instantations 
should be at the library level (if you are using Gnat, they should be
in a file of their own). This allows you the freedom to with the 
package at other places in the program.

Also if you want a quick clean up of the code, replace any instantiation of
integer_io (integer) with a "with Ada.Integer_Text_IO" in the context clause.


Dale




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

* Re: Generic Packages
  1998-08-10  0:00 Generic Packages Tory Patnoe
                   ` (2 preceding siblings ...)
  1998-08-12  0:00 ` Dale Stanbrough
@ 1998-08-17  0:00 ` Dr. Hubert B. Keller
  1998-08-27  0:00   ` Simon Wright
  3 siblings, 1 reply; 25+ messages in thread
From: Dr. Hubert B. Keller @ 1998-08-17  0:00 UTC (permalink / raw)




Tory Patnoe schrieb:

> package int_io is new integer_io; use int_io;

"use int_io;" makes no sense at this point.
Write this after the importing statement (with) of a package.
H.K.





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

* Re: Generic Packages
  1998-08-17  0:00 ` Dr. Hubert B. Keller
@ 1998-08-27  0:00   ` Simon Wright
  0 siblings, 0 replies; 25+ messages in thread
From: Simon Wright @ 1998-08-27  0:00 UTC (permalink / raw)


"Dr. Hubert B. Keller" <keller@iai.fzk.de> writes:

> Tory Patnoe schrieb:
> 
> > package int_io is new integer_io; use int_io;
> 
> "use int_io;" makes no sense at this point.
> Write this after the importing statement (with) of a package.

It makes perfect sense; without it you would need to write
  int_io.put(1);
with it, just
  put(1);

See LRM 8.4(6) ff




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

* Generic packages
@ 2000-02-16  0:00 David Olsson
  2000-02-16  0:00 ` R. Tim Coslet
  0 siblings, 1 reply; 25+ messages in thread
From: David Olsson @ 2000-02-16  0:00 UTC (permalink / raw)


If I want to make a generic package with a function as a generic
parameter to the package, and that function returns a value of a
specifik enumeration, so where can I define that enumeration. I can't do
before generic and if I put it between generic and package, than the
compiler thinks its a generic parameter to package and complains that it
should be defined as (<>) or something. If I put it after package, then
it wont be visible for the function. I guess you can put it in a
seperate ads file, but that isn't pretty in my opinion. Is there another
way ?

/David





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

* Re: Generic packages
  2000-02-16  0:00 Generic packages David Olsson
@ 2000-02-16  0:00 ` R. Tim Coslet
  0 siblings, 0 replies; 25+ messages in thread
From: R. Tim Coslet @ 2000-02-16  0:00 UTC (permalink / raw)


Put the Generic package inside a package containing definitions for all
types that the Generic package requires (that aren't defined elsewhere).

Either that or make the Generic package a child of the package containing
the type definitions.

David Olsson wrote:

> If I want to make a generic package with a function as a generic
> parameter to the package, and that function returns a value of a
> specifik enumeration, so where can I define that enumeration. I can't do
> before generic and if I put it between generic and package, than the
> compiler thinks its a generic parameter to package and complains that it
> should be defined as (<>) or something. If I put it after package, then
> it wont be visible for the function. I guess you can put it in a
> seperate ads file, but that isn't pretty in my opinion. Is there another
> way ?
>
> /David







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

* Re: Generic Packages
  2001-04-19 21:27 Generic Packages Eyal Ben-gal
@ 2001-04-19 20:26 ` Ehud Lamm
  2001-04-19 22:09 ` Robert A Duff
  1 sibling, 0 replies; 25+ messages in thread
From: Ehud Lamm @ 2001-04-19 20:26 UTC (permalink / raw)


First thing you have to realize is that when you want a generic unit to work
ona private or limited private type, the package must somehow be told how to
work with objects of the opaque type.

Basically, you do this by supplying routines as generic parameters. These
routines are the ones that know how to use the type (they usually come from
the package that exports the time). They, in essence, provide an interface
that the generic unit needs in order to work with the type. This is a
restricted form of the itnerface exported by the ADT package.

I usually describe this situation with the following metahpor.There is a
secrect, and this secret is how to handle the abstract data type. You want
to pass this secret to the generic unit. However generic units don't have
ears so you can't just lean over and whisper the secret. What you do is
package the secret inside a routine (a more techincal term would be
"procedural abstraction") and pass the routine to the generic unit.

This subject is explained very well in the Ada83 Ratioanale chapter on
generic units. I highly recommend reading it (you instructor should have a
copy of this chapter, and you can also find it online).

Good luck with the assignment!

Ehud Lamm





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

* Generic Packages
@ 2001-04-19 21:27 Eyal Ben-gal
  2001-04-19 20:26 ` Ehud Lamm
  2001-04-19 22:09 ` Robert A Duff
  0 siblings, 2 replies; 25+ messages in thread
From: Eyal Ben-gal @ 2001-04-19 21:27 UTC (permalink / raw)


I have two packages for implementing a polynom.
In the first package I'm using linked list (PolyList) and the second is an
array (Fixed_Polynom)
both of the packeges supporting the same package interface such as:
"+", "-", SetFirst, SetNext, GetElement,

I've tried to create a generic package which will implement
"*", drivation calculation, print and so on.  (lets call this packes
general_pol) which ofcourse using the SetFirst, SetNext functions

when I'm using general_pol with the decleration of explicit type which will
be the type to use from the abstruct types of the erlier packages there is
no problem,

but when i'm trying to make it generic I fail since I'm calling the abstruct
data type functions and the compiler ofcourse can't know how to connect that
to the type I'm using for the SetFirst, SetNext functions.

How can I do that ?
generic

type Polynom is private

package general_Pol is

function sum (frst :Polynom; scnd :Polynom) return Polynom;

function "*" (first:Polynom; second:Polynom) return Polynom;

function derive (plnm:Polynom) return Polynom;

procedure print (plnm:in out Polynom);

function "=" (first:Polynom; second:Polynom) return boolean;

function SetPolynom return Polynom;

function Count (x:Polynom) return integer;

end general_Pol;



How can I create it Generic that will implement in first instatiation for
PolyList the additional operations,

and later the same for Fixed_Polynom.

Thanks,

        Eyal.






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

* Re: Generic Packages
  2001-04-19 21:27 Generic Packages Eyal Ben-gal
  2001-04-19 20:26 ` Ehud Lamm
@ 2001-04-19 22:09 ` Robert A Duff
  2001-04-20  6:50   ` Ehud Lamm
  1 sibling, 1 reply; 25+ messages in thread
From: Robert A Duff @ 2001-04-19 22:09 UTC (permalink / raw)


"Eyal Ben-gal" <eyalbengal@hotmail.com> writes:

> but when i'm trying to make it generic I fail since I'm calling the abstruct
> data type functions and the compiler ofcourse can't know how to connect that
> to the type I'm using for the SetFirst, SetNext functions.
> 
> How can I do that ?

You can either pass in all the operations, or you can use a generic
formal derived type, where the ancestor type has the operations.

- Bob



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

* Re: Generic Packages
  2001-04-19 22:09 ` Robert A Duff
@ 2001-04-20  6:50   ` Ehud Lamm
  0 siblings, 0 replies; 25+ messages in thread
From: Ehud Lamm @ 2001-04-20  6:50 UTC (permalink / raw)


Robert A Duff <bobduff@world.std.com> wrote in message
news:wccwv8g7da3.fsf@world.std.com...
> "Eyal Ben-gal" <eyalbengal@hotmail.com> writes:
>
> > but when i'm trying to make it generic I fail since I'm calling the
abstruct
> > data type functions and the compiler ofcourse can't know how to connect
that
> > to the type I'm using for the SetFirst, SetNext functions.
> >
> > How can I do that ?
>
> You can either pass in all the operations, or you can use a generic
> formal derived type, where the ancestor type has the operations.
>


Eyal, we'll use the seond technique Robert Duff mentions after we learn
about inheritance in Ada.

Ehud Lamm





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

* generic packages
@ 2002-07-09 13:03 Sami Evangelista
  2002-07-09 13:28 ` Fabien Garcia
  2002-07-10  2:00 ` SteveD
  0 siblings, 2 replies; 25+ messages in thread
From: Sami Evangelista @ 2002-07-09 13:03 UTC (permalink / raw)


hello everybody

i have declared a package generic_set like this :
-------------------------------------------------
generic
    type Element is private;
    with function "=" (E1, E2 : in Element) return boolean;
package Generic_Set is
    type Set_Record is private;
    type Set is private;
     .....
private
    type Set is access Set_record;
    type Set_record is record
       El : Element;
       Others_Els : Set;
    end record;
end Generic_Set;
-------------------------------------------------


now i want to declare a generic function which take a A set and return a 
B set according to a function wich take a A element and return B 
element. I have tried this in the generic_set.ads file, but gnat crashes 
(???):
--------------------------------------------------
generic
      with package a_set is new generic_set(<>);
      with package b_set is new generic_set(<>);
      with function a_to_b(A : in a_set.element) return b_set.element;
function a_set_to_b_set(the_set : in a_set.set) return b_set.set;
-------------------------------------------------


is there any solution ?

thanks for any help


Sami Evangelista
sami.evangelista@wanadoo.fr




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

* Re: generic packages
  2002-07-09 13:03 generic packages Sami Evangelista
@ 2002-07-09 13:28 ` Fabien Garcia
  2002-07-09 13:41   ` Sami Evangelista
  2002-07-10  2:00 ` SteveD
  1 sibling, 1 reply; 25+ messages in thread
From: Fabien Garcia @ 2002-07-09 13:28 UTC (permalink / raw)


Sami Evangelista wrote:
 > [snip]

> is there any solution ?
> 
> thanks for any help
I would try something like this :


-----------------------------------------------------------------
generic
      type Element_a is private;
      type element_b is private;
      with function eq_a (E1, E2 : in Element_a) return boolean;
      with function eq_b (E1, E2 : in Element_b) return boolean;		
      with function a_to_b(A : in Element_a) return element_b;
package A_Set_To_B_set_pack is

package a_set is new generic_set (Element_a,eq_a);
package b_set is new generic_set (Element_b,eq_b);

function a_set_to_b_set(the_set : in a_set.set) return b_set.set;
------------------------------------------------------------------
Fabien Garcia






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

* Re: generic packages
  2002-07-09 13:28 ` Fabien Garcia
@ 2002-07-09 13:41   ` Sami Evangelista
  0 siblings, 0 replies; 25+ messages in thread
From: Sami Evangelista @ 2002-07-09 13:41 UTC (permalink / raw)




Fabien Garcia wrote:

> Sami Evangelista wrote:
>  > [snip]
> 
>> is there any solution ?
>>
>> thanks for any help
> 
> I would try something like this :
> 
> 
> -----------------------------------------------------------------
> generic
>      type Element_a is private;
>      type element_b is private;
>      with function eq_a (E1, E2 : in Element_a) return boolean;
>      with function eq_b (E1, E2 : in Element_b) return boolean;       
>      with function a_to_b(A : in Element_a) return element_b;
> package A_Set_To_B_set_pack is
> 
> package a_set is new generic_set (Element_a,eq_a);
> package b_set is new generic_set (Element_b,eq_b);
> 
> function a_set_to_b_set(the_set : in a_set.set) return b_set.set;
> ------------------------------------------------------------------
> Fabien Garcia
> 
> 
> 

thank you for your response.

but is it possible to declare it in the generic_set.ads file?
i have tried to put a_set_to_b_set into another file but then i can't 
access to the private type of the generic_set package like el or others_els.




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

* Re: generic packages
  2002-07-09 13:03 generic packages Sami Evangelista
  2002-07-09 13:28 ` Fabien Garcia
@ 2002-07-10  2:00 ` SteveD
  2002-07-11 13:41   ` Sami Evangelista
  1 sibling, 1 reply; 25+ messages in thread
From: SteveD @ 2002-07-10  2:00 UTC (permalink / raw)


"Sami Evangelista" <sami.evangelista@wanadoo.fr> wrote in message
news:3D2ADF27.8070502@wanadoo.fr...
[snip]
> now i want to declare a generic function which take a A set and return a
> B set according to a function wich take a A element and return B
> element. I have tried this in the generic_set.ads file, but gnat crashes

The following code compiles with no crashes using gnat-3.14p-nt.exe on
Windows 2000.
=======================================================
procedure test is
generic
    type Element is private;
    with function "=" (E1, E2 : in Element) return boolean;
package Generic_Set is
    type Set_Record is private;
    type Set is private;
--     .....
private
    type Set is access Set_record;
    type Set_record is record
       El : Element;
       Others_Els : Set;
    end record;
end Generic_Set;

generic
      with package a_set is new generic_set(<>);
      with package b_set is new generic_set(<>);
      with function a_to_b(A : in a_set.element) return b_set.element;
function a_set_to_b_set(the_set : in a_set.set) return b_set.set;

function a_set_to_b_set(the_set : in a_set.set) return b_set.set is
  dummy : b_set.Set;
begin
  return dummy;
end a_set_to_b_set;

begin
  null;
end test;
==============================================
It's not very useful as it is, I just wanted to reproduce your crash.

SteveD







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

* Re: generic packages
  2002-07-10  2:00 ` SteveD
@ 2002-07-11 13:41   ` Sami Evangelista
  2002-07-11 20:56     ` Adam Beneschan
  0 siblings, 1 reply; 25+ messages in thread
From: Sami Evangelista @ 2002-07-11 13:41 UTC (permalink / raw)


thank you for your response, but does the following code compile?

=======================================================
--file generic_set.ads

generic
      type Element is private;
      with function "=" (E1, E2 : in Element) return boolean;
package Generic_Set is
      type Set_Record is private;
      type Set is private;
      generic
           with package a_set is new generic_set(<>);
           with package b_set is new generic_set(<>);
           with function a_to_b(A : in a_set.element) return 

                                               b_set.element;
      function a_set_to_b_set(the_set : in a_set.set) return b_set.set;


private
      type Set is access Set_record;
      type Set_record is record
         El : Element;
         Others_Els : Set;
      end record;
end Generic_Set;
=======================================================

Sami Evangelista




SteveD wrote:

> "Sami Evangelista" <sami.evangelista@wanadoo.fr> wrote in message
> news:3D2ADF27.8070502@wanadoo.fr...
> [snip]
> 
>>now i want to declare a generic function which take a A set and return a
>>B set according to a function wich take a A element and return B
>>element. I have tried this in the generic_set.ads file, but gnat crashes
>>
> 
> The following code compiles with no crashes using gnat-3.14p-nt.exe on
> Windows 2000.
> =======================================================
> procedure test is
> generic
>     type Element is private;
>     with function "=" (E1, E2 : in Element) return boolean;
> package Generic_Set is
>     type Set_Record is private;
>     type Set is private;
> --     .....
> private
>     type Set is access Set_record;
>     type Set_record is record
>        El : Element;
>        Others_Els : Set;
>     end record;
> end Generic_Set;
> 
> generic
>       with package a_set is new generic_set(<>);
>       with package b_set is new generic_set(<>);
>       with function a_to_b(A : in a_set.element) return b_set.element;
> function a_set_to_b_set(the_set : in a_set.set) return b_set.set;
> 
> function a_set_to_b_set(the_set : in a_set.set) return b_set.set is
>   dummy : b_set.Set;
> begin
>   return dummy;
> end a_set_to_b_set;
> 
> begin
>   null;
> end test;
> ==============================================
> It's not very useful as it is, I just wanted to reproduce your crash.
> 
> SteveD
> 
> 
> 
> 
> 




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

* Re: generic packages
  2002-07-11 13:41   ` Sami Evangelista
@ 2002-07-11 20:56     ` Adam Beneschan
  0 siblings, 0 replies; 25+ messages in thread
From: Adam Beneschan @ 2002-07-11 20:56 UTC (permalink / raw)


Sami Evangelista <sami.evangelista@wanadoo.fr> wrote in message news:<3D2D8B01.9040303@wanadoo.fr>...
> thank you for your response, but does the following code compile?
> 
> =======================================================
> --file generic_set.ads
> 
> generic
>       type Element is private;
>       with function "=" (E1, E2 : in Element) return boolean;
> package Generic_Set is
>       type Set_Record is private;
>       type Set is private;
>       generic
>            with package a_set is new generic_set(<>);
>            with package b_set is new generic_set(<>);
>            with function a_to_b(A : in a_set.element) return 
> 
>                                                b_set.element;
>       function a_set_to_b_set(the_set : in a_set.set) return b_set.set;
> 
> 
> private
>       type Set is access Set_record;
>       type Set_record is record
>          El : Element;
>          Others_Els : Set;
>       end record;
> end Generic_Set;
> =======================================================
> 
> Sami Evangelista

The code, as you've written it, is illegal.  Within the declarative
region of Generic_Set, if you use the name Generic_Set, it denotes the
*current* *instance* of the generic, rather than the generic itself. 
Thus, since Generic_Set doesn't denote a generic in this context, it
can't be used where a generic is expected in this formal package
declaration:

    with package a_set is new generic_set(<>);

See 8.6(18), 12.1(11).

				-- Adam



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

end of thread, other threads:[~2002-07-11 20:56 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-09 13:03 generic packages Sami Evangelista
2002-07-09 13:28 ` Fabien Garcia
2002-07-09 13:41   ` Sami Evangelista
2002-07-10  2:00 ` SteveD
2002-07-11 13:41   ` Sami Evangelista
2002-07-11 20:56     ` Adam Beneschan
  -- strict thread matches above, loose matches on Subject: below --
2001-04-19 21:27 Generic Packages Eyal Ben-gal
2001-04-19 20:26 ` Ehud Lamm
2001-04-19 22:09 ` Robert A Duff
2001-04-20  6:50   ` Ehud Lamm
2000-02-16  0:00 Generic packages David Olsson
2000-02-16  0:00 ` R. Tim Coslet
1998-08-10  0:00 Generic Packages Tory Patnoe
1998-08-11  0:00 ` Tucker Taft
1998-08-11  0:00 ` Robert I. Eachus
1998-08-12  0:00 ` Dale Stanbrough
1998-08-17  0:00 ` Dr. Hubert B. Keller
1998-08-27  0:00   ` Simon Wright
     [not found] <5e03nm$esq@netty.york.ac.uk>
1997-02-15  0:00 ` Jon S Anthony
1997-02-20  0:00 ` phtruong
1997-02-21  0:00   ` Robert Dewar
1997-02-25  0:00     ` Quorlia
1997-02-27  0:00       ` Robert Dewar
     [not found] <4inq3c$lr9@NNTP.MsState.Edu>
1996-03-22  0:00 ` John Herro
1996-03-22  0:00   ` Samuel Tardieu

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