comp.lang.ada
 help / color / mirror / Atom feed
* Help on extending a private record from a private record with a generic attribute...
@ 1998-04-16  0:00 Christopher Campise
  1998-04-16  0:00 ` Tucker Taft
  0 siblings, 1 reply; 5+ messages in thread
From: Christopher Campise @ 1998-04-16  0:00 UTC (permalink / raw)



Ada95 on a Rational Apex compiler:
I have a "superclass" with a private record consisiting of a generic
type attribute.  I need to inherit this from within another package but
am receiving compiler errors stating that "a record extension will be
provided iff the parent record is tagged," (which it is).  Is this even
legal?  I looked everywhere for examples and found none that relate to
this, adahome.com, Programming in Ada95, Rendezvous with Ada95, plus
other tutorials.  Any ideas?

For example:

***********
generic
   type Value_Class is private;

package Generic is
   type Class is tagged private;
         .
         .

private
   type Class is tagged
      record
         Some_Value : Value_Class;
      end record;

end Generic;

***********

with Generic;

package MyPackage is
    type Class is new Generic.Class with private;  -> Message: "CLASS
(2nd one) denotes no component of Generic; a record extension

will be provided iff  parent type is a tagged type" (which it is)
                .
                .
private
   type Class is new Generic.Class with    ->   Message: "CLASS (2nd
one) denotes no component of Generic; a record extension

record
will be provided iff  parent type is a tagged type" (which it is)
         Index : Integer;
      end record;
end MyPackage;
***********

--
Chris Campise, Associate Engineer     phone:  (716)631-0610 x384
Amherst Systems Inc.                         fax:    (716)631-0629
30 Wilson Road                                 E-Mail: crc@amherst.com
Buffalo, NY 14221                            WWW: www.amherst.com






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

* Re: Help on extending a private record from a private record with a generic attribute...
  1998-04-16  0:00 Help on extending a private record from a private record with a generic attribute Christopher Campise
@ 1998-04-16  0:00 ` Tucker Taft
  1998-04-17  0:00   ` Assistance " Anonymous
  0 siblings, 1 reply; 5+ messages in thread
From: Tucker Taft @ 1998-04-16  0:00 UTC (permalink / raw)



Christopher Campise (crc@amherst.com) wrote:

: Ada95 on a Rational Apex compiler:
: I have a "superclass" with a private record consisiting of a generic
: type attribute.  I need to inherit this from within another package but
: am receiving compiler errors stating that "a record extension will be
: provided iff the parent record is tagged," (which it is).  Is this even
: legal?  I looked everywhere for examples and found none that relate to
: this, adahome.com, Programming in Ada95, Rendezvous with Ada95, plus
: other tutorials.  Any ideas?

You cannot select items from a generic package.  You must
first instantiate the generic package, and select items from
the instance.  

: For example:

: ***********
: generic
:    type Value_Class is private;

: package Generic is
:    type Class is tagged private;
:          .
:          .

: private
:    type Class is tagged
:       record
:          Some_Value : Value_Class;
:       end record;

: end Generic;

I presume you didn't really call it "Generic" since that
is an Ada reserved word...

: ***********

: with Generic;

: package MyPackage is
:     type Class is new Generic.Class with private;  -> Message: "CLASS
: (2nd one) denotes no component of Generic; a record extension

: will be provided iff  parent type is a tagged type" (which it is)

This message is misleading you.  The problem is that "Generic" is
a generic package, rather than a (non-generic) package.  You cannot
select anything from a generic package.  

You need something like:

    with Generic;
    package Instance is new Generic(My_Value_Class);

and then refer to Instance.Class.  If you don't want to
instantiate first, then you need to define a new generic which
has a formal package, e.g.:

   with Generic;
   generic 
       with package Instance is new Generic(<>);
   package MyPackage is
       type Class is new Instance.Class with private;
    ...

:                 .
:                 .
: private
:    type Class is new Generic.Class with    ->   Message: "CLASS (2nd
: one) denotes no component of Generic; a record extension
: record
: will be provided iff  parent type is a tagged type" (which it is)

Same problem.  "Generic" is a generic, not an instance.

:          Index : Integer;
:       end record;
: end MyPackage;
: ***********

: --
: Chris Campise, Associate Engineer     phone:  (716)631-0610 x384
: Amherst Systems Inc.                         fax:    (716)631-0629
: 30 Wilson Road                                 E-Mail: crc@amherst.com
: Buffalo, NY 14221                            WWW: www.amherst.com

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




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

* Re: Assistance on extending a private record from a private record with a generic attribute...
  1998-04-16  0:00 ` Tucker Taft
@ 1998-04-17  0:00   ` Anonymous
  1998-04-17  0:00     ` Tucker Taft
  1998-04-17  0:00     ` Christopher Campise
  0 siblings, 2 replies; 5+ messages in thread
From: Anonymous @ 1998-04-17  0:00 UTC (permalink / raw)



<35364E81.94B51B0F@amherst.com>

On Thu, 16 Apr 1998 21:26:10 GMT, stt@houdini.camb.inmet.com (Tucker
Taft) wrote:

> Christopher Campise (crc@amherst.com) wrote:
> 
> : Ada95 on a Rational Apex compiler:
> : I have a "superclass" with a private record consisiting of a generic
> : type attribute.  I need to inherit this from within another package but
> : am receiving compiler errors stating that "a record extension will be
> : provided iff the parent record is tagged," (which it is).  Is this even
> : legal?  I looked everywhere for examples and found none that relate to
> : this, adahome.com, Programming in Ada95, Rendezvous with Ada95, plus
> : other tutorials.  Any ideas?
> 
> You cannot select items from a generic package.  You must
> first instantiate the generic package, and select items from
> the instance.  
> 
> : For example:
> 
> : ***********
> : generic
> :    type Value_Class is private;
> 
> : package Generic is
> :    type Class is tagged private;
> ...

Surprisingly, even Tucker Taft did not point out that you cannot have a
package named Generic. "generic" is a reserved word.

Assuming that you change the name, perhaps to Generic_Class, then you
still don't have a package, so you can't refer to its type Class. You
need to instantiate the generic:

package My_Class is new Generic_Class (Value_Class => My_Type);

Now you have a package named My_Class, and may refer to My_Class.Class.

Jeff Carter  PGP:1024/440FBE21
My real e-mail address: ( carter @ innocon . com )
"Son of a window-dresser."
Monty Python & the Holy Grail

Posted with Spam Hater - see
http://www.compulink.co.uk/~net-services/spam/




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

* Re: Assistance on extending a private record from a private record with a generic attribute...
  1998-04-17  0:00   ` Assistance " Anonymous
  1998-04-17  0:00     ` Tucker Taft
@ 1998-04-17  0:00     ` Christopher Campise
  1 sibling, 0 replies; 5+ messages in thread
From: Christopher Campise @ 1998-04-17  0:00 UTC (permalink / raw)



Thanks for your help, but with all due respect ,on Tucker's behalf, he did
point out that 'generic' is a reserved word in his reply to my inquiry.

But on another note, if I have a private record type extension from my generic
package and I want to extend THIS record to create a 3 level inheritance tree:

My generic class
****
generic
   type Value_Class is tagged private;

package My_Generic is
   type Class is tagged private;
    ...

private
   type Class is tagged
      record
         Some_Value : Value_Class;
      end record;
end My_Generic;
***

***
with my_generic;

generic
   with package My_Class is new My_Generic(<>);

package My_Class is
   type Class is new My_Class.Class with private;
...

private
   type Class is new My_Class.Class with
      record
         Value1 : Integer;
         Value2 : Integer;
      end record;
end My_Class;

If I wanted to extend My_Class, would the following be acceptable?

***
with my_class;

package another_class is
   type Class is new my_Class.class with private;
...

private
   type class is new my_class with
      record
         another_value : Integer;
      end;
end another_class;

Please excuse my ignorance.  I'm fairly new to Ada95.

Anonymous wrote:

> <35364E81.94B51B0F@amherst.com>
>
> On Thu, 16 Apr 1998 21:26:10 GMT, stt@houdini.camb.inmet.com (Tucker
> Taft) wrote:
>
> > Christopher Campise (crc@amherst.com) wrote:
> >
> > : Ada95 on a Rational Apex compiler:
> > : I have a "superclass" with a private record consisiting of a generic
> > : type attribute.  I need to inherit this from within another package but
> > : am receiving compiler errors stating that "a record extension will be
> > : provided iff the parent record is tagged," (which it is).  Is this even
> > : legal?  I looked everywhere for examples and found none that relate to
> > : this, adahome.com, Programming in Ada95, Rendezvous with Ada95, plus
> > : other tutorials.  Any ideas?
> >
> > You cannot select items from a generic package.  You must
> > first instantiate the generic package, and select items from
> > the instance.
> >
> > : For example:
> >
> > : ***********
> > : generic
> > :    type Value_Class is private;
> >
> > : package Generic is
> > :    type Class is tagged private;
> > ...
>
> Surprisingly, even Tucker Taft did not point out that you cannot have a
> package named Generic. "generic" is a reserved word.
>
> Assuming that you change the name, perhaps to Generic_Class, then you
> still don't have a package, so you can't refer to its type Class. You
> need to instantiate the generic:
>
> package My_Class is new Generic_Class (Value_Class => My_Type);
>
> Now you have a package named My_Class, and may refer to My_Class.Class.
>
> Jeff Carter  PGP:1024/440FBE21
> My real e-mail address: ( carter @ innocon . com )
> "Son of a window-dresser."
> Monty Python & the Holy Grail
>
> Posted with Spam Hater - see
> http://www.compulink.co.uk/~net-services/spam/



--
Christopher Campise, Associate Engineer
Amherst Systems Inc.
30 Wilson Road
Buffalo, NY 14221
phone:  (716)631-0610 x384
E-Mail: crc@amherst.com
WWW: www.amherst.com






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

* Re: Assistance on extending a private record from a private record with a generic attribute...
  1998-04-17  0:00   ` Assistance " Anonymous
@ 1998-04-17  0:00     ` Tucker Taft
  1998-04-17  0:00     ` Christopher Campise
  1 sibling, 0 replies; 5+ messages in thread
From: Tucker Taft @ 1998-04-17  0:00 UTC (permalink / raw)



Jeff Carter wrote:

: Surprisingly, even Tucker Taft did not point out that you cannot have a
: package named Generic. "generic" is a reserved word.

For the record ;-), I did point out in my earlier response ...

> I presume you didn't really call it "Generic" since that
> is an Ada reserved word...

: Jeff Carter  PGP:1024/440FBE21
: My real e-mail address: ( carter @ innocon . com )

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




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

end of thread, other threads:[~1998-04-17  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-16  0:00 Help on extending a private record from a private record with a generic attribute Christopher Campise
1998-04-16  0:00 ` Tucker Taft
1998-04-17  0:00   ` Assistance " Anonymous
1998-04-17  0:00     ` Tucker Taft
1998-04-17  0:00     ` Christopher Campise

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