comp.lang.ada
 help / color / mirror / Atom feed
* why does this work?  private new types.
@ 2002-05-06 14:24 chris.danx
  2002-05-06 14:57 ` Jean-Pierre Rosen
  0 siblings, 1 reply; 7+ messages in thread
From: chris.danx @ 2002-05-06 14:24 UTC (permalink / raw)


Hi,

This example code will explain it better than I can.


with hash_tables;  -- generic
package blah is

   subtype word is string (some_range);

   type table is private;

   procedure add (a : in word;
                  t : in out table);

   ...

   private
      ... -- some functions in here

      package tables is new hash_tables
         (items => word,
          size => 100, -- for quickyness!
          hash_function => hash_function,
          equals => equals, to_string => to_string);

      type table is new tables.hash_table;

end blah;


package body blah is

   procedure add (a : in word;
                  t : in out table) is
   begin
      insert (a, t); -- *** here ***
   end add;

end blah;


insert is defined in hash_tables, so why can it be used in the body of blah
without "using" it?  Is it implicitly "used" when table is defined as a
'new' hash_table (i.e. it's allowed to be used .  That'd kindof make sense,
but is this the correct way to think of it, or is there a better way?

Seems like you learn new things about Ada every day!


Thanks,
Chris





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

* Re: why does this work?  private new types.
  2002-05-06 14:24 why does this work? private new types chris.danx
@ 2002-05-06 14:57 ` Jean-Pierre Rosen
  2002-05-06 15:28   ` chris.danx
  2002-05-09 17:05   ` Kai Schuelke
  0 siblings, 2 replies; 7+ messages in thread
From: Jean-Pierre Rosen @ 2002-05-06 14:57 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 831 bytes --]


"chris.danx" <spamoff.danx@ntlworld.com> a �crit dans le message news: MmwB8.927$hg3.319129@news11-gui.server.ntli.net...
>
>       type table is new tables.hash_table;
>[...]
> insert is defined in hash_tables, so why can it be used in the body of blah
> without "using" it?  Is it implicitly "used" when table is defined as a
> 'new' hash_table (i.e. it's allowed to be used .  That'd kindof make sense,
> but is this the correct way to think of it, or is there a better way?
>
When you derive a type, all derived operations are declared *at the point of derivation*.
Therefore, the Insert for Table is declared immediately inside your package, and thus directly visible.

--
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





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

* Re: why does this work?  private new types.
  2002-05-06 14:57 ` Jean-Pierre Rosen
@ 2002-05-06 15:28   ` chris.danx
  2002-05-09 17:05   ` Kai Schuelke
  1 sibling, 0 replies; 7+ messages in thread
From: chris.danx @ 2002-05-06 15:28 UTC (permalink / raw)



"Jean-Pierre Rosen" <rosen@adalog.fr> wrote in message
news:ab65j7$cfe$1@s1.read.news.oleane.net...

> When you derive a type, all derived operations are declared *at the point
of derivation*.
> Therefore, the Insert for Table is declared immediately inside your
package, and thus directly visible.

Thanks Jean-Pierre, I understand now!


Chris





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

* Re: why does this work?  private new types.
  2002-05-06 14:57 ` Jean-Pierre Rosen
  2002-05-06 15:28   ` chris.danx
@ 2002-05-09 17:05   ` Kai Schuelke
  2002-05-09 17:17     ` David C. Hoos
  2002-05-09 17:29     ` Stephen Leake
  1 sibling, 2 replies; 7+ messages in thread
From: Kai Schuelke @ 2002-05-09 17:05 UTC (permalink / raw)


Hello,

I am new to this newsgroup, and to ada, too. I read trough the latest
news to find something to learn and got the following:

> >       type table is new tables.hash_table;
[..]
> When you derive a type, all derived operations are declared *at the
point of derivation*.
> Therefore, the Insert for Table is declared immediately inside your
package, and thus directly visible.

Does that mean that INSERT is an Operation like "+" or "mod"? Or is
INSERT just a normal procedure? I can't imagine the last, but I never
heard/read about an INSERT Operator, either. It would be nice is
somebody could answer that question.

Thanks

Kai Schuelke






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

* Re: why does this work?  private new types.
  2002-05-09 17:05   ` Kai Schuelke
@ 2002-05-09 17:17     ` David C. Hoos
  2002-05-09 17:29     ` Stephen Leake
  1 sibling, 0 replies; 7+ messages in thread
From: David C. Hoos @ 2002-05-09 17:17 UTC (permalink / raw)



----- Original Message ----- 
From: "Kai Schuelke" <kai.schuelke@gmx.net>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Thursday, May 09, 2002 12:05 PM
Subject: Re: why does this work? private new types.
<snip>

> Does that mean that INSERT is an Operation like "+" or "mod"? Or is
> INSERT just a normal procedure? I can't imagine the last, but I never
> heard/read about an INSERT Operator, either. It would be nice is
> somebody could answer that question.
> 

Operations include both functions and procedures, whereas _operator_
is a special kind of function like abs, mod, +, -, *, **, and /, etc.




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

* Re: why does this work?  private new types.
  2002-05-09 17:05   ` Kai Schuelke
  2002-05-09 17:17     ` David C. Hoos
@ 2002-05-09 17:29     ` Stephen Leake
  2002-05-10  2:14       ` Jeffrey Carter
  1 sibling, 1 reply; 7+ messages in thread
From: Stephen Leake @ 2002-05-09 17:29 UTC (permalink / raw)


"Kai Schuelke" <kai.schuelke@gmx.net> writes:

> > >       type table is new tables.hash_table;
> [..]
> > When you derive a type, all derived operations are declared *at the
> point of derivation*.
> > Therefore, the Insert for Table is declared immediately inside your
> package, and thus directly visible.
> 
> Does that mean that INSERT is an Operation like "+" or "mod"? Or is
> INSERT just a normal procedure? I can't imagine the last, but I never
> heard/read about an INSERT Operator, either. It would be nice is
> somebody could answer that question.

In Ada, the phrase "operation of a type" means any subprogram
that takes a parameter of the type or returns a result of the type.

The term "operator" refers to "+", "*" etc.

So INSERT is an "operation of type hash_table", but not an "operator".
And "+" is an operator, not an operation.

Every language has its own jargon :).

-- 
-- Stephe



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

* Re: why does this work?  private new types.
  2002-05-09 17:29     ` Stephen Leake
@ 2002-05-10  2:14       ` Jeffrey Carter
  0 siblings, 0 replies; 7+ messages in thread
From: Jeffrey Carter @ 2002-05-10  2:14 UTC (permalink / raw)


Stephen Leake wrote:
> 
> And "+" is an operator, not an operation.

"+" is both an operation and an operator. Not all operations are
operators, but all operators are operations.

-- 
Jeff Carter
"Nobody expects the Spanish Inquisition!"
Monty Python's Flying Circus



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

end of thread, other threads:[~2002-05-10  2:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-06 14:24 why does this work? private new types chris.danx
2002-05-06 14:57 ` Jean-Pierre Rosen
2002-05-06 15:28   ` chris.danx
2002-05-09 17:05   ` Kai Schuelke
2002-05-09 17:17     ` David C. Hoos
2002-05-09 17:29     ` Stephen Leake
2002-05-10  2:14       ` Jeffrey Carter

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