comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: A bunch of questions that come after "Hello world"
Date: Thu, 14 Nov 2002 21:51:15 GMT
Date: 2002-11-14T21:51:15+00:00	[thread overview]
Message-ID: <wccisyzvmzw.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 5ad0dd8a.0211140218.6d48be15@posting.google.com

wojtek@power.com.pl (Wojtek Narczynski) writes:

> Robert A Duff <bobduff@shell01.TheWorld.com> wrote in message news:<wcck7jhfar3.fsf@shell01.TheWorld.com>...
> > wojtek@power.com.pl (Wojtek Narczynski) writes:
> > 
> > > 2. Could somebody confirm that I cannot define a procedure / function
> > > as a member of a "record", but I sure can as a member of "protected"?
> > 
> > You can define a record component of an access-to-subprogram type.
> > But what you probably want is a dispatching subprogram of a tagged type.
> > 
> 
> The code below illustrates my dillema.
> 
> package Test is
> 
>     -- why not: 'type Door is protected'?
>     -- Is this because protected_type_declaration 
>     -- is supposed to resemble task_type_declaration?

Yes.  So why not "type T is task..." instead of "task type T is..."?
No good reason -- the syntax ought to be more consistent.

>     protected type Door is
>     
>         procedure Open;
>         procedure Close;
>         function Can_Go_Thru return Boolean;
>     
>     private
>     
>         State: Boolean := False;
>     
>     end Door;
> 
>     
>     type Door_Nogo is record 
>     
>         -- can't put function / procedure here?
>         -- procedure Open;
>         -- procedure Close;
>         -- function Can_Go_Thru return Boolean;

As I said in my previous post, if you are used to doing this in C++ or
Java or whatever, what you want to do in Ada is declare dispatching
operations.  They are declared *outside* the type.  And the "self"
parameter is not passed by magic -- you just pass an ordinary
parameter.  So the syntax is different from what you're used to,
but the semantics is pretty much the same.

I think you really need to look at a tutorial or textbook on this.

>         Status: Boolean := False;
> 
>     end record;

> end Test;
> 
> I have two more questions:
> 1. Is there something like super in Java?

Yes.  You use a type conversion to convert the parameter on which you're
dispatching to its parent type.  This is the "self" parameter that some
other languages pass implicitly -- in Ada, it is passed explicitly, and
you call it by whatever name you like (not necessarily Self).

> 2. Can I overload () operator? I guess no.

No.

- Bob



  parent reply	other threads:[~2002-11-14 21:51 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-13 20:44 A bunch of questions that come after "Hello world" Wojtek Narczynski
2002-11-13 20:57 ` Robert A Duff
2002-11-14 10:18   ` Wojtek Narczynski
2002-11-14 11:21     ` David C. Hoos, Sr.
2002-11-14 19:51     ` tmoran
2002-11-14 21:51     ` Robert A Duff [this message]
2002-11-15 17:50       ` Wojtek Narczynski
2002-11-15 23:07         ` Robert A Duff
2002-11-18 10:24           ` Wojtek Narczynski
2002-11-18 11:54             ` Dmitry A. Kazakov
2002-11-18 16:24               ` Wojtek Narczynski
2002-11-18 21:19                 ` Robert A Duff
2002-11-19  8:48                 ` Dmitry A. Kazakov
2002-11-13 22:06 ` Martin Dowie
2002-11-14 17:48   ` Pascal Obry
2002-11-14 18:53     ` David C. Hoos
2002-11-14 22:36     ` Martin Dowie
2002-11-15  1:25       ` Jeffrey Carter
2002-11-13 22:31 ` Stephen Leake
  -- strict thread matches above, loose matches on Subject: below --
2002-11-18 10:32 Grein, Christoph
replies disabled

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