comp.lang.ada
 help / color / mirror / Atom feed
* Can you use arrays from another package ?
@ 2002-05-21 22:28 Jon
  2002-05-21 23:31 ` tmoran
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Jon @ 2002-05-21 22:28 UTC (permalink / raw)


say the main program is calle MAIN.ADB

and uses 2 packages X and Y

if there is an array of records in X called A.

how do i use the array A in Y ?

e.g

package body X is
    type R is record
        hi : string;
        bye : integer;
    end record;

    A : array(1..10) of R;

end X;


now in Y, how do i use that array ? ive tried this :

package body Y is

    get( X.A(1).hi );

end Y;


but it doesnt work, does anyone know how to do it ?


thanks






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

* Re: Can you use arrays from another package ?
  2002-05-21 22:28 Can you use arrays from another package ? Jon
@ 2002-05-21 23:31 ` tmoran
  2002-05-21 23:37 ` Dale Stanbrough
  2002-05-22  1:52 ` Robert Dewar
  2 siblings, 0 replies; 15+ messages in thread
From: tmoran @ 2002-05-21 23:31 UTC (permalink / raw)


> package body X is
> ...
> package body Y is
>   get( X.A(1).hi );
  You can't see inside another package's body.  You can only see things
in its public specification part.  So drop the word "body" on package X.
(I assume you have a "with X;" for Y)



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

* Re: Can you use arrays from another package ?
  2002-05-21 22:28 Can you use arrays from another package ? Jon
  2002-05-21 23:31 ` tmoran
@ 2002-05-21 23:37 ` Dale Stanbrough
  2002-05-22  1:47   ` Jeffrey Carter
  2002-05-22  6:13   ` Adrian Hoe
  2002-05-22  1:52 ` Robert Dewar
  2 siblings, 2 replies; 15+ messages in thread
From: Dale Stanbrough @ 2002-05-21 23:37 UTC (permalink / raw)


Jon wrote:

> say the main program is calle MAIN.ADB
> 
> and uses 2 packages X and Y
> 
> if there is an array of records in X called A.
> 
> how do i use the array A in Y ?
> 
> e.g
> 
> package body X is
>     type R is record
>         hi : string;
>         bye : integer;
>     end record;
> 
>     A : array(1..10) of R;
> 
> end X;
> 
> 
> now in Y, how do i use that array ? ive tried this :

you need a "with, use" clause at the start of either 
Y's package spec, or it's package body.

You'll also need to wrap up the call to get inside
a procedure...

e.g.


  with X; use X;
> package body Y is

procedure Get_Hi is
begin
>     get( X.A(1).hi );
end;

> 
> end Y;


That's how to get it working; however i think it's a bad
design. My design rule is "never declare variables in a
package spec".

The declaration of A would be better in Main, and then
you pass it into procedure Get_Hi as a parameter.

A big mistake that people make it to treat packages as
objects - a good way to view them is just as a place where
type declarations and subprograms go.
(this is not quite the only way to view them, but it's a 
good first step).


Dale



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

* Re: Can you use arrays from another package ?
  2002-05-21 23:37 ` Dale Stanbrough
@ 2002-05-22  1:47   ` Jeffrey Carter
  2002-05-22  6:13   ` Adrian Hoe
  1 sibling, 0 replies; 15+ messages in thread
From: Jeffrey Carter @ 2002-05-22  1:47 UTC (permalink / raw)


Dale Stanbrough wrote:
> 
> A big mistake that people make it to treat packages as
> objects - a good way to view them is just as a place where
> type declarations and subprograms go.
> (this is not quite the only way to view them, but it's a
> good first step).

I disagree. I think it's good to treat packages as objects. However,
it's important to remember that the data in objects must be hidden.
Thus, the visible specification of an object implemented as a package
contains only type declarations, constant declarations, subprogram
specifications, and comments.

-- 
Jeff Carter
"I blow my nose on you."
Monty Python & the Holy Grail



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

* Re: Can you use arrays from another package ?
  2002-05-21 22:28 Can you use arrays from another package ? Jon
  2002-05-21 23:31 ` tmoran
  2002-05-21 23:37 ` Dale Stanbrough
@ 2002-05-22  1:52 ` Robert Dewar
  2002-05-22 12:11   ` Jon
  2 siblings, 1 reply; 15+ messages in thread
From: Robert Dewar @ 2002-05-22  1:52 UTC (permalink / raw)


"Jon" <jkjw@brighton.ac.uk> wrote in message news:<acehkr$2v5$1@saturn.bton.ac.uk>...
> say the main program is calle MAIN.ADB
> 
> and uses 2 packages X and Y
> 
> if there is an array of records in X called A.
> 
> how do i use the array A in Y ?

This is a pretty fundamental question. If you are having trouble
understanding this from your text book (look up WITH statements),
then perhaps you might find it useful to try running an online
tutorial (check out the resources at www.adapower.com)



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

* Re: Can you use arrays from another package ?
  2002-05-21 23:37 ` Dale Stanbrough
  2002-05-22  1:47   ` Jeffrey Carter
@ 2002-05-22  6:13   ` Adrian Hoe
  1 sibling, 0 replies; 15+ messages in thread
From: Adrian Hoe @ 2002-05-22  6:13 UTC (permalink / raw)


Dale Stanbrough <dstanbro@bigpond.net.au> wrote in message news:<dstanbro-23D11A.09373422052002@mec2.bigpond.net.au>...
> Jon wrote:
> 
> > say the main program is calle MAIN.ADB
> > 
> > and uses 2 packages X and Y
> > 
> > if there is an array of records in X called A.
> > 
> > how do i use the array A in Y ?
> > 
> > e.g
> > 
> > package body X is
> >     type R is record
> >         hi : string;
> >         bye : integer;
> >     end record;
> > 
> >     A : array(1..10) of R;
> > 
> > end X;
> > 
> > 
> > now in Y, how do i use that array ? ive tried this :
> 
> you need a "with, use" clause at the start of either 
> Y's package spec, or it's package body.
> 
> You'll also need to wrap up the call to get inside
> a procedure...
> 
> e.g.
> 
> 
>   with X; use X;
> > package body Y is
> 
> procedure Get_Hi is
> begin
> >     get( X.A(1).hi );
> end;
> 
> > 
> > end Y;
> 
> 
> That's how to get it working; however i think it's a bad
> design. My design rule is "never declare variables in a
> package spec".
> 
> The declaration of A would be better in Main, and then
> you pass it into procedure Get_Hi as a parameter.
> 
> A big mistake that people make it to treat packages as
> objects - a good way to view them is just as a place where
> type declarations and subprograms go.
> (this is not quite the only way to view them, but it's a 
> good first step).
> 
> 
> Dale



SOmetimes it is difficult to say which is bad design. It depends on
the purpose and what is your approach in designing your software.

One still can have array A declared in package spec. In some cases,
you would want to declare private (or declare in the package body) and
have a procedure to read/write to the array. You hide it away from
other package but provide a nice way for access.

Sometimes, you just need to declare it public.


-- 
                                       -- Adrian Hoe
                                       -- http://adrianhoe.com



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

* Re: Can you use arrays from another package ?
  2002-05-22  1:52 ` Robert Dewar
@ 2002-05-22 12:11   ` Jon
  2002-05-22 12:36     ` Preben Randhol
  0 siblings, 1 reply; 15+ messages in thread
From: Jon @ 2002-05-22 12:11 UTC (permalink / raw)


if i try that program i keep getting

"A" no declared in "X"


so you are saying instead of declaring the type in package body X, i should
declare it public in the package spec X ?





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

* Re: Can you use arrays from another package ?
  2002-05-22 12:11   ` Jon
@ 2002-05-22 12:36     ` Preben Randhol
  2002-05-22 15:16       ` Jon
  2002-05-22 22:22       ` Robert Dewar
  0 siblings, 2 replies; 15+ messages in thread
From: Preben Randhol @ 2002-05-22 12:36 UTC (permalink / raw)


On Wed, 22 May 2002 13:11:03 +0100, Jon wrote:
> if i try that program i keep getting
> 
> "A" no declared in "X"
> 
> 
> so you are saying instead of declaring the type in package body X, i should
> declare it public in the package spec X ?

No you should declare it private in the package spec and then use a
function/procedure to get it. 

Is this an assignment?

Preben



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

* Re: Can you use arrays from another package ?
  2002-05-22 12:36     ` Preben Randhol
@ 2002-05-22 15:16       ` Jon
  2002-05-22 19:17         ` Preben Randhol
  2002-05-22 22:22       ` Robert Dewar
  1 sibling, 1 reply; 15+ messages in thread
From: Jon @ 2002-05-22 15:16 UTC (permalink / raw)


i know the rules of not doing peoples homework :)

but yeah it is an assignement, but that is not a question i was asked to fo,
its something i need to know to help my assignment.


"Preben Randhol" <randhol+abuse@pvv.org> wrote in message
news:slrnaen45p.2jh.randhol+abuse@kiuk0156.chembio.ntnu.no...
> On Wed, 22 May 2002 13:11:03 +0100, Jon wrote:
> > if i try that program i keep getting
> >
> > "A" no declared in "X"
> >
> >
> > so you are saying instead of declaring the type in package body X, i
should
> > declare it public in the package spec X ?
>
> No you should declare it private in the package spec and then use a
> function/procedure to get it.
>
> Is this an assignment?
>
> Preben





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

* Re: Can you use arrays from another package ?
  2002-05-22 15:16       ` Jon
@ 2002-05-22 19:17         ` Preben Randhol
  0 siblings, 0 replies; 15+ messages in thread
From: Preben Randhol @ 2002-05-22 19:17 UTC (permalink / raw)


On Wed, 22 May 2002 16:16:35 +0100, Jon wrote:
> i know the rules of not doing peoples homework :)
> 
> but yeah it is an assignement, but that is not a question i was asked to fo,
> its something i need to know to help my assignment.

Ok read =>

   http://www.it.bton.ac.uk/staff/je/adacraft/ch04.htm#4.7

Preben
-- 
�.., chaos is found in greatest abundance wherever order is being
sought. It always defeats order, because it is better organized.�
                            -- Interesting Times, Terry Pratchett



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

* Re: Can you use arrays from another package ?
  2002-05-22 12:36     ` Preben Randhol
  2002-05-22 15:16       ` Jon
@ 2002-05-22 22:22       ` Robert Dewar
  2002-05-24  4:17         ` Richard Riehle
  2002-05-24 10:07         ` John English
  1 sibling, 2 replies; 15+ messages in thread
From: Robert Dewar @ 2002-05-22 22:22 UTC (permalink / raw)


Preben Randhol <randhol+abuse@pvv.org> wrote in message news:<slrnaen45p.2jh.randhol+abuse@kiuk0156.chembio.ntnu.no>...

> Is this an assignment?

Sure, almost certainly, we know these brighton.ac.uk messages pretty well :-)



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

* Re: Can you use arrays from another package ?
  2002-05-22 22:22       ` Robert Dewar
@ 2002-05-24  4:17         ` Richard Riehle
  2002-05-24 13:41           ` Larry Kilgallen
  2002-06-01 11:19           ` Georg Bauhaus
  2002-05-24 10:07         ` John English
  1 sibling, 2 replies; 15+ messages in thread
From: Richard Riehle @ 2002-05-24  4:17 UTC (permalink / raw)


Robert Dewar wrote:

> Preben Randhol <randhol+abuse@pvv.org> wrote in message news:<slrnaen45p.2jh.randhol+abuse@kiuk0156.chembio.ntnu.no>...
>
> > Is this an assignment?
>
> Sure, almost certainly, we know these brighton.ac.uk messages pretty well :-)

Good heavens!   I hope my NPS students are clever enough to disguise
their origins when in pursuit of help with homework assignments.  :-)

Richard Riehle






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

* Re: Can you use arrays from another package ?
  2002-05-22 22:22       ` Robert Dewar
  2002-05-24  4:17         ` Richard Riehle
@ 2002-05-24 10:07         ` John English
  1 sibling, 0 replies; 15+ messages in thread
From: John English @ 2002-05-24 10:07 UTC (permalink / raw)


Robert Dewar wrote:
> 
> Preben Randhol <randhol+abuse@pvv.org> wrote in message news:<slrnaen45p.2jh.randhol+abuse@kiuk0156.chembio.ntnu.no>...
> 
> > Is this an assignment?
> 
> Sure, almost certainly, we know these brighton.ac.uk messages pretty well :-)

...and, as usual, I watch with interest as the story unfolds... :-)

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------



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

* Re: Can you use arrays from another package ?
  2002-05-24  4:17         ` Richard Riehle
@ 2002-05-24 13:41           ` Larry Kilgallen
  2002-06-01 11:19           ` Georg Bauhaus
  1 sibling, 0 replies; 15+ messages in thread
From: Larry Kilgallen @ 2002-05-24 13:41 UTC (permalink / raw)


In article <3CEDBEEA.B09ABD72@adaworks.com>, Richard Riehle <richard@adaworks.com> writes:
> Robert Dewar wrote:
> 
>> Preben Randhol <randhol+abuse@pvv.org> wrote in message news:<slrnaen45p.2jh.randhol+abuse@kiuk0156.chembio.ntnu.no>...
>>
>> > Is this an assignment?
>>
>> Sure, almost certainly, we know these brighton.ac.uk messages pretty well :-)
> 
> Good heavens!   I hope my NPS students are clever enough to disguise
> their origins when in pursuit of help with homework assignments.  :-)

Perhaps they hack into brighton.ac.uk to post their questions :-)



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

* Re: Can you use arrays from another package ?
  2002-05-24  4:17         ` Richard Riehle
  2002-05-24 13:41           ` Larry Kilgallen
@ 2002-06-01 11:19           ` Georg Bauhaus
  1 sibling, 0 replies; 15+ messages in thread
From: Georg Bauhaus @ 2002-06-01 11:19 UTC (permalink / raw)


Richard Riehle <richard@adaworks.com> wrote:
:    I hope my NPS students are clever enough to disguise
: their origins when in pursuit of help with homework assignments.  :-)

I'd hope they don't. One  thing I like in a teaching situation
is a good and open relation between teacher and student--both know
each other, including homework difficulties. Fraud is The Bad Thing.
No smiley.

Georg Bauhaus



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

end of thread, other threads:[~2002-06-01 11:19 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-21 22:28 Can you use arrays from another package ? Jon
2002-05-21 23:31 ` tmoran
2002-05-21 23:37 ` Dale Stanbrough
2002-05-22  1:47   ` Jeffrey Carter
2002-05-22  6:13   ` Adrian Hoe
2002-05-22  1:52 ` Robert Dewar
2002-05-22 12:11   ` Jon
2002-05-22 12:36     ` Preben Randhol
2002-05-22 15:16       ` Jon
2002-05-22 19:17         ` Preben Randhol
2002-05-22 22:22       ` Robert Dewar
2002-05-24  4:17         ` Richard Riehle
2002-05-24 13:41           ` Larry Kilgallen
2002-06-01 11:19           ` Georg Bauhaus
2002-05-24 10:07         ` John English

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