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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.42.39.145 with SMTP id h17mr16614678ice.24.1423331007897; Sat, 07 Feb 2015 09:43:27 -0800 (PST) X-Received: by 10.140.106.8 with SMTP id d8mr100249qgf.7.1423331007764; Sat, 07 Feb 2015 09:43:27 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!hl2no11469460igb.0!news-out.google.com!q4ni11076qan.0!nntp.google.com!v8no7250674qal.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 7 Feb 2015 09:43:27 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=83.99.113.5; posting-account=sDyr7QoAAAA7hiaifqt-gaKY2K7OZ8RQ NNTP-Posting-Host: 83.99.113.5 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: A few questions From: Laurent Injection-Date: Sat, 07 Feb 2015 17:43:27 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Received-Bytes: 3753 X-Received-Body-CRC: 3485472487 Xref: news.eternal-september.org comp.lang.ada:24919 Date: 2015-02-07T09:43:27-08:00 List-Id: Hi 1) Trying to implement a search function in my linked list. Doesn't compile because the return type :List_Ptr is not visible in the ads file? spec: function Search (L : in List; Element : in Element_Type) return List_Ptr; -- Pre: L is defined; L may be empty; Element is a scalar type -- Post: returns access to found node body function Search (L : in List; Element : in Element_Type) return List_Ptr is Temp : List_Ptr; Current : List; begin Current := L.Head; while Current.Head /= null loop if Equals(Current.Head.Element, Element) then Temp:= Current.Head; return Temp; end if; Current.Head := Current.Head.Next; end loop; end Search; The List_Ptr is defined as: private ---------- -- List -- ---------- type List_Node; type List_Ptr is access List_Node; type List_Node is record Element : Element_Type; Next : List_Ptr; Previous:List_Ptr; end record; type List is record Head : List_Ptr; Tail : List_Ptr; end record; I have put the search function in a child package. 2) Tried the same thing but this time using an iterator but fails with 65:20 (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2)) 65:20 return by reference not permitted in Ada 2005 on return It; spec function Search (L : access List; Element : Element_Type) return Iterator; -- Pre: L is defined; L may be empty; Element is a scalar type -- Post: returns access to found node body function Search (L : access List; Element : Element_Type) return Iterator is It : Iterator (L); begin Start (It); while not Done (It) loop if Equals (It.This.Element, Element) then return It; end if; Next(It); end loop; end Search; The Iterator is defined as: private -------------- -- Iterator -- -------------- type Iterator (L : access List) is limited record This : List_Ptr; end record; I have tried to understand RM-2005 6.5(5.5/2) but don't know what "If the result subtype of the function is defined by a subtype_mark, the return_subtype_indication shall be a subtype_indication. The type of the subtype_indication shall be the result type of the function" is supposed to look like. If someone could enlighten me on both problems. https://github.com/Chutulu/Chapter-15.git 3) How can I take a look at the assembler code of both versions? Just curious to see if there is actually a difference between both versions. I have no idea of assembler but that doesn't keep me from trying. Thanks Laurent