comp.lang.ada
 help / color / mirror / Atom feed
* Trouble with renaming types
@ 2001-05-08 15:37 Bob McChesney
  2001-05-08 15:45 ` Bob McChesney
  2001-05-09 13:18 ` Stephen Leake
  0 siblings, 2 replies; 8+ messages in thread
From: Bob McChesney @ 2001-05-08 15:37 UTC (permalink / raw)


Can anyone help me with this problem I have please?

I'm instantiating a generic package Set_Class from within another package. I
instantiate the package as WordSet, and this means a resulting type that I
need to use is WordSet.Set. However, I want to be able to reference this
type under another name from outside the package (I want to call it
Dictionary).

I think I'm supposed to just use a subtype order (subtype Dictionary is
WordSet.Set), however I'm keeping the instantiation of the package private,
which means I can't do this unless I put the subtype order after the
instantiation (which would place it inside the private area and it doesn't
like that).

So can anyone tell me a way of renaming a private type, inside a package?
That would be really good.

So far the only way it's worked is to take everything out of private but
this is not how I need it.

Any help would be much appreciated!

Thanks,
Bob





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

* Re: Trouble with renaming types
  2001-05-08 15:37 Trouble with renaming types Bob McChesney
@ 2001-05-08 15:45 ` Bob McChesney
  2001-05-08 16:45   ` Mark
  2001-05-09 13:18 ` Stephen Leake
  1 sibling, 1 reply; 8+ messages in thread
From: Bob McChesney @ 2001-05-08 15:45 UTC (permalink / raw)


Oh, forgot to mention, I'm not using:

'type Dictionary is new WordSet.Set'

because when I do that all the functions of WordSet cannot operate on type
Dictionary.

What I need is to be able to give type WordSet.Set a new name, but still
allow all oof the WordSet functions/procedures to be able to work on it.

Sorry.





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

* Re: Trouble with renaming types
  2001-05-08 15:45 ` Bob McChesney
@ 2001-05-08 16:45   ` Mark
  2001-05-08 17:12     ` Bob McChesney
  0 siblings, 1 reply; 8+ messages in thread
From: Mark @ 2001-05-08 16:45 UTC (permalink / raw)



"Bob McChesney" <bob@teambob.freeserve.co.uk> wrote in message
news:9d949f$kto$1@newsg1.svr.pol.co.uk...
> Oh, forgot to mention, I'm not using:
>
> 'type Dictionary is new WordSet.Set'
>
> because when I do that all the functions of WordSet cannot operate on type
> Dictionary.

Yes and no... subprograms defined immediately within Wordset, if they
operate on type Set, are "primitive operations" of Set and will be inherited
(think of that as "duplicated") for type Dictionary.

But subprograms defined elsewhere that operate operate on Set are not part
of type Set, so they can't be inherited by Dictionary.

>
> What I need is to be able to give type WordSet.Set a new name, but still
> allow all oof the WordSet functions/procedures to be able to work on it.
>

To "alias" a type with an interchangeable name, say this:

    subtype Dictionary is Wordset.Set;

(note, no "new" in there... :-)

Have fun,
-- mark






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

* Re: Trouble with renaming types
  2001-05-08 16:45   ` Mark
@ 2001-05-08 17:12     ` Bob McChesney
  0 siblings, 0 replies; 8+ messages in thread
From: Bob McChesney @ 2001-05-08 17:12 UTC (permalink / raw)


Hmm, maybe I'm doing it wrong then...

When I use the 1st method (i.e. new type of WordSet.Set) what you said about
inherited procedures doesn't seem to hold for me.

eg, I've instantiated WordSet.

So ... in WordSet I have:
a type defined called Set
a procedure Add(Set, Word)

I've made type Dictionary a new WordSet.Set (which it allows no problem).

BUT when I try and do:

WordSet(Dictionary, Word) I get the compilation error:

Expected private type "Set" .... found private type "Dictionary".

Any ideas?

Thanks
Bob

"Mark" <up.yerz@nospam.com> wrote in message
news:%oVJ6.129347$xN4.8316100@news1.sttls1.wa.home.com...
>
> "Bob McChesney" <bob@teambob.freeserve.co.uk> wrote in message
> news:9d949f$kto$1@newsg1.svr.pol.co.uk...
> > Oh, forgot to mention, I'm not using:
> >
> > 'type Dictionary is new WordSet.Set'
> >
> > because when I do that all the functions of WordSet cannot operate on
type
> > Dictionary.
>
> Yes and no... subprograms defined immediately within Wordset, if they
> operate on type Set, are "primitive operations" of Set and will be
inherited
> (think of that as "duplicated") for type Dictionary.
>
> But subprograms defined elsewhere that operate operate on Set are not part
> of type Set, so they can't be inherited by Dictionary.
>
> >
> > What I need is to be able to give type WordSet.Set a new name, but still
> > allow all oof the WordSet functions/procedures to be able to work on it.
> >
>
> To "alias" a type with an interchangeable name, say this:
>
>     subtype Dictionary is Wordset.Set;
>
> (note, no "new" in there... :-)
>
> Have fun,
> -- mark
>
>
>





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

* Re: Trouble with renaming types
@ 2001-05-09  4:59 Christoph Grein
  2001-05-09 15:15 ` Bob McChesney
  0 siblings, 1 reply; 8+ messages in thread
From: Christoph Grein @ 2001-05-09  4:59 UTC (permalink / raw)
  To: comp.lang.ada

Bob, I'm not sure what you're about; your text is too brief and marred with 
errors:

>  WordSet(Dictionary, Word) I get the compilation error:

I gather you mean

  WordSet.Add (Dictionary, Word);

The problem is here that you qualify Add with the wrong prefix. Dictionary is 
not defined in WordSet but in some other parent (let's also call it Parent), and 
you must use the parent name as prefix:

   Parent.Add (Dictionary, Word);

See the following example as further illustration:

generic
  type Formal is private;
package Gen is
  type Stuff is private;
  procedure Primitive (X: in Stuff);
private
  type Stuff is record
    Comp: Formal;
  end record;
end Gen;
---------
with Gen;
package Inst is new Gen (Formal => Integer);  -- want to rename Inst.Stuff
----------
with Inst;
package What_I_want is          -- kind of renaming
  type Goal is new Inst.Stuff;  -- implicitly inherits Primitive operations
end What_I_want;
-----------------
with What_I_want;
procedure Main is
  X: What_I_want.Goal;
begin
  What_I_want.Primitive (X);
end Main;
  
Christoph





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

* Re: Trouble with renaming types
  2001-05-08 15:37 Trouble with renaming types Bob McChesney
  2001-05-08 15:45 ` Bob McChesney
@ 2001-05-09 13:18 ` Stephen Leake
  2001-05-09 15:22   ` Bob McChesney
  1 sibling, 1 reply; 8+ messages in thread
From: Stephen Leake @ 2001-05-09 13:18 UTC (permalink / raw)


"Bob McChesney" <bob@teambob.freeserve.co.uk> writes:

> Can anyone help me with this problem I have please?
> 
> I'm instantiating a generic package Set_Class from within another package. I
> instantiate the package as WordSet, and this means a resulting type that I
> need to use is WordSet.Set. However, I want to be able to reference this
> type under another name from outside the package (I want to call it
> Dictionary).
> 
> I think I'm supposed to just use a subtype order (subtype Dictionary is
> WordSet.Set), however I'm keeping the instantiation of the package private,
> which means I can't do this unless I put the subtype order after the
> instantiation (which would place it inside the private area and it doesn't
> like that).
> 
> So can anyone tell me a way of renaming a private type, inside a package?
> That would be really good.

The only way to get a public type that is a "renaming" of a private
type is to introduce a layer:

with Set_Class;
package Foo

    type Dictionary is private;

private
    package WordSet is new Set_Class (...);

    type Dictionary is record
        Words : WordSet.Set;
    end record;

end Foo;

> So far the only way it's worked is to take everything out of private
> but this is not how I need it.

It would help if you could expand on why it is not appropriate to make
WordSet public. If you are building an additional abstraction layer,
then you will probably find other items to put in the Dictionary
record type, which will make it seem less painful.

-- 
-- Stephe



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

* Re: Trouble with renaming types
  2001-05-09  4:59 Christoph Grein
@ 2001-05-09 15:15 ` Bob McChesney
  0 siblings, 0 replies; 8+ messages in thread
From: Bob McChesney @ 2001-05-09 15:15 UTC (permalink / raw)


Hi Christoph

Sorry about the mistakes in my code. I was very scruffy due to lack of
sleep. However I've caught up on some now, and your message has solved the
problem for me.

Thanks very much for your help. It's very clever that Ada instantiates like
that (or at least I think so being a relative beginner).

Cheers,
Bob





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

* Re: Trouble with renaming types
  2001-05-09 13:18 ` Stephen Leake
@ 2001-05-09 15:22   ` Bob McChesney
  0 siblings, 0 replies; 8+ messages in thread
From: Bob McChesney @ 2001-05-09 15:22 UTC (permalink / raw)


Thanks for your message Stephen.

I've managed to get this instantiation malarkey working thatks to Christoph.

The reason I was keeping the type private is what I'm being taught so that I
learn to keep the functions on a type within it's package. My reference to
moving things out of private was regarding the fact that I could get things
to work with a subtype declaration but that can only be done if the type
that subtype is deriving from is non-private [at least that was my
experience. I don't want to argue against anyone about it though =) ].

I thought something was going wrong with my type declaration, but it was in
fact my later call of the type's functons.

Thanks very much to everyone who's provided their assistance.

Bob





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

end of thread, other threads:[~2001-05-09 15:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-08 15:37 Trouble with renaming types Bob McChesney
2001-05-08 15:45 ` Bob McChesney
2001-05-08 16:45   ` Mark
2001-05-08 17:12     ` Bob McChesney
2001-05-09 13:18 ` Stephen Leake
2001-05-09 15:22   ` Bob McChesney
  -- strict thread matches above, loose matches on Subject: below --
2001-05-09  4:59 Christoph Grein
2001-05-09 15:15 ` Bob McChesney

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