From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5ac1c1813029999b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-14 13:52:26 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!news.stealth.net!news.stealth.net!66.250.146.10.MISMATCH!newshosting.com!news-xfer1.atl.newshosting.com!uunet!dca.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: A bunch of questions that come after "Hello world" User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Thu, 14 Nov 2002 21:51:15 GMT Content-Type: text/plain; charset=us-ascii References: <5ad0dd8a.0211131244.42603699@posting.google.com> <5ad0dd8a.0211140218.6d48be15@posting.google.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Organization: The World Public Access UNIX, Brookline, MA Xref: archiver1.google.com comp.lang.ada:30906 Date: 2002-11-14T21:51:15+00:00 List-Id: wojtek@power.com.pl (Wojtek Narczynski) writes: > Robert A Duff wrote in message news:... > > 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