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=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f5b0e4b29b2f0c99,start X-Google-Attributes: gid103376,public From: "Daniel Wengelin" Subject: Who is right? Gnat or http://www.adahome.com/articles/1998-02/ar_lessons95.html? Date: 1999/04/07 Message-ID: <01be80c2$114e0890$c24d3a8b@m04w0588>#1/1 X-Deja-AN: 463543023 X-Complaints-To: abuse@global-ip.net X-Trace: news3.global-ip.net 923467293 4935 139.58.232.1 (7 Apr 1999 06:41:33 GMT) Organization: Global One Services NNTP-Posting-Date: 7 Apr 1999 06:41:33 GMT Newsgroups: comp.lang.ada Date: 1999-04-07T06:41:33+00:00 List-Id: When looking around for some infomration about OOP I came across the article http://www.adahome.com/articles/1998-02/ar_lessons95.html. When skimming through, I noted the following section ----------------------------------------- COPY FROM ADAHOME --------------------------------- The ability to pass subprograms as parameters is one of the nicest features of Ada 95 (it didn't exist in Ada 83). But accessibility rules make it useless within a multi-tasking program. Indeed, access to a local procedure cannot be used as a parameter of a more globally declared procedure (e.g. a class method). In practice, accessibility rules force the use of global variable which makes multi-tasking very delicate. The only alternative is to use generic parameters (parameterized methods), with the inconvenience that parameterized methods are not inheritable. Example: The following looks nice, but it will not compile! generic type Item is private; package List is type Object is ... ... type Action is access procedure Action( The_Item : in out Item; Stop_Iterating : out Boolean); procedure Iterate ( The_Action : Action Through : in List.Object); ... end List; with List, Student; package Student_List is new List (Item => Student.Object); with Student_List; function Retrieve_Student (With_Name : Student.Name; From : Student_List.Object) return Student.Object is The_Student_Found : Student.Object; procedure Find (The_Student : in out Student.Object; Stop_Iterating : out Boolean) is begin if Student.Name_Of (The_Student) = With_Name then The_Student_Found := The_Student; Stop_Iterating := True; else Stop_Iterating := False; end if; end Find; begin Student_List.Iterate (The_Action => Find'Access, -- Compilation Error Through => From); return The_Student_Found; end Retrieve_Student; ------------------------------------- END COPY FROM ADAHOME --------------------------------- I gave the code a try with Gnat 3.11 as follows. generic type Item_T is private; package List is type Node; type Object is access Node; type Node is record I : Item_T; Next:Object; end record; type Action_Proc is access procedure (I : in out Item_T); procedure Iterate (The_Action : Action_Proc; Through_List : Object); end List; --------------------------- package body List is procedure Iterate (The_Action : Action_Proc; Through_List : Object) is Current : Object := Through_List; begin while Current /= null loop The_Action(Current.I); Current := Current.Next; end loop; end Iterate; end List; ------------------------ procedure List_Test is procedure Print (C: in out Character) is begin Ada.Text_Io.Put(C); Ada.Text_Io.New_Line; end Print; package C_List is new List(Character); The_List : C_List.Object := null; begin for I in Character range 'a' .. 'e' loop The_List := new C_List.Node'(I, The_List); end loop; C_List.Iterate (Print'Access, The_List); end List_Test; The above source compiled and ran without any problems. So, did I misunderstand or is Gnat wrong or is the article in AdaHome wrong? thanks. Daniel