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-Thread: 103376,dbcfe2b0a74da57e X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!198.186.194.251.MISMATCH!news-out.readnews.com!transit4.readnews.com!panix!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Inherited Methods and such Date: Fri, 28 Sep 2007 15:42:09 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1190239986.762473.204290@k79g2000hse.googlegroups.com> <1rw45b3rmvmcr$.1df4wst5oknbl$.dlg@40tude.net> <1190296353.624737.150940@y42g2000hsy.googlegroups.com> <11m13st1f92kf$.m8s6y8mc8ebk.dlg@40tude.net> <1190321119.206313.65290@57g2000hsv.googlegroups.com> <1190408526.100291.265040@50g2000hsm.googlegroups.com> <9ukf2wtqjs0q$.iuijmal4x56b$.dlg@40tude.net> <1190497995.498679.119190@19g2000hsx.googlegroups.com> <1mw3qju08q8uj.sgzht7ld9ydc$.dlg@40tude.net> <1190579805.451187.71140@d55g2000hsg.googlegroups.com> <1i8ksr774bjbj.vpmnx3c0i9qz.dlg@40tude.net> <1190646125.024072.310020@19g2000hsx.googlegroups.com> <1r9s9v6pcjifl.vp4ktk0unpd1.dlg@40tude.net> <1190753631.240548.101820@19g2000hsx.googlegroups.com> <1190843408.713838.128690@g4g2000hsf.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1191008531 11324 192.74.137.71 (28 Sep 2007 19:42:11 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 28 Sep 2007 19:42:11 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:cNfT/S5k0xOCt3VC3TLL2yF4ZFE= Xref: g2news2.google.com comp.lang.ada:2198 Date: 2007-09-28T15:42:09-04:00 List-Id: Robert A Duff writes: > Maciej Sobczak writes: >> Constructor functions in Ada are functions that return new objects >> (most useful for limited types since Ada 2005) can have parameters, >> but they still don't acknowledge the "progressive" nature of the whole >> process. > > I think they do, actually. Here's an example. What do you think? Do you revise your opinion that Ada doesn't properly support constructors? We've got a Root_Window type, and a type derived from that, for "red" windows (OK, I didn't bother with something more realistic). Note that this example dispatches during construction, and dispatches the way C++ constructors would (shallow, not deep). But I think we both agree that dispatching at all during construction is questionable. (There's an AI on this issue, by the way.) Maybe Root_Window should have unknown discriminants (<>), to force the use of the provided constructors. I get this output, using the latest (internal to AdaCore) version of GNAT: Evilly dispatching from Make_Root_Window. Hello from Class_Wide Hello from Primitive (Root_Window) Goodbye from Class_Wide Evilly dispatching from Make_Red_Window. Hello from Class_Wide Hello from Primitive (Red_Window) Goodbye from Class_Wide Hello from Class_Wide Hello from Primitive (Red_Window) Goodbye from Class_Wide And here's the code: with Ada.Text_IO; use Ada.Text_IO; package Root_Windows is type Root_Window is tagged limited private; procedure Primitive (Win : Root_Window); procedure Class_Wide (Win : Root_Window'Class); private type Root_Window is tagged limited record X : Integer; end record; end Root_Windows; package Root_Windows.Factory is function Make_Root_Window (X : Integer) return Root_Window; end Root_Windows.Factory; with Ada.Text_IO; use Ada.Text_IO; with Root_Windows; use Root_Windows; package Red_Windows is type Red_Window is new Root_Window with private; procedure Primitive (Win : Red_Window); private type Red_Window is new Root_Window with record Y : Integer; end record; end Red_Windows; package Red_Windows.Factory is function Make_Red_Window (X, Y : Integer) return Red_Window; end Red_Windows.Factory; package body Root_Windows is procedure Primitive (Win : Root_Window) is begin Put_Line ("Hello from Primitive (Root_Window)"); end Primitive; procedure Class_Wide (Win : Root_Window'Class) is begin Put_Line ("Hello from Class_Wide"); Primitive (Win); -- dispatch Put_Line ("Goodbye from Class_Wide"); end Class_Wide; end Root_Windows; package body Root_Windows.Factory is function Make_Root_Window (X : Integer) return Root_Window is begin return Result : Root_Window := (X => X) do Put_Line ("Evilly dispatching from Make_Root_Window."); Class_Wide (Result); end return; end Make_Root_Window; end Root_Windows.Factory; package body Red_Windows is procedure Primitive (Win : Red_Window) is begin Put_Line ("Hello from Primitive (Red_Window)"); end Primitive; end Red_Windows; with Root_Windows.Factory; package body Red_Windows.Factory is function Make_Red_Window (X, Y : Integer) return Red_Window is begin return Result : Red_Window := (Root_Windows.Factory.Make_Root_Window (X) with Y => Y) do Put_Line ("Evilly dispatching from Make_Red_Window."); Class_Wide (Result); end return; end Make_Red_Window; end Red_Windows.Factory; with Red_Windows.Factory; procedure Red_Windows.Test is My_Window : Root_Window'Class := Factory.Make_Red_Window (X => 1, Y => 2); begin Class_Wide (My_Window); end Red_Windows.Test;