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.236.36.39 with SMTP id v27mr13312694yha.24.1423435023676; Sun, 08 Feb 2015 14:37:03 -0800 (PST) X-Received: by 10.140.31.134 with SMTP id f6mr146600qgf.33.1423435023637; Sun, 08 Feb 2015 14:37:03 -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!border2.nntp.dca1.giganews.com!nntp.giganews.com!j7no506835qaq.0!news-out.google.com!q4ni11076qan.0!nntp.google.com!v8no7576767qal.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 8 Feb 2015 14:37:03 -0800 (PST) In-Reply-To: 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 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: A few questions From: Laurent Injection-Date: Sun, 08 Feb 2015 22:37:03 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:24924 Date: 2015-02-08T14:37:03-08:00 List-Id: On Saturday, February 7, 2015 at 11:14:46 PM UTC+1, Brad Moore wrote: > One way to get around this, is to define List_Ptr as a private type in=20 > the visible part of the package. >=20 > eg. >=20 > type List_Ptr is private; Ok that makes sense. As the package is based on an example from my Ada95 bo= ok, only the List type is visible. But the author had probably a good reaso= n to design it like this?=20 > A child package isn't necessary for this purpose. Has to do with the fact that the "Insert_In_Order" procedure requires overr= iding of >=3D and <, if Element_Type is a record... So a child package make= s things easier if I don't need this procedure. Same is true for the search= function which requires an overridden =3D. So I put it in the child packag= e.=20 > > 65:20 (Ada 2005) cannot copy object of a limited type (RM-2005= 6.5(5.5/2)) Oops wrong paragraphe, indeed meant 6.5(5.5/2) copied the wrong one > The compiler is complaining because you have declared It as a local=20 > object inside your Search function, and you are trying to return that=20 > object as the result of a function call, which involves copying the=20 > object to wherever the result of the function call is to be placed. >=20 > Limited types are not copyable. Is there a reason why you declared your= =20 > Iterator type to be a limited type, (ie. with the keyword limited)? No idea why it is limited. Took the example of the active iterator from Joh= n Barnes Ada 2005 book.=20 But again I suppose that the author had a good reason to make the Iterator = limited? > If you do want it to be a limited type you can return an object of that= =20 > type in a function call in certain contexts. You have to use an extended= =20 > return statement though. >=20 > See RM 6.5 (2.1/2) and 6.5 (28/2) for an example. >=20 > That would allow the return object to be built in place where the=20 > function result is to be placed, and thus avoids copying any object. >=20 > Such a function that returns a limited type is usable only to initialize= =20 > a declaration of a limited type. You cannot use it to change the value=20 > of the limited type once it has been initialized. This may be too=20 > restrictive for your needs, so perhaps you should consider not making=20 > this type limited. >=20 Hm yes was peaking inside the double_linked_list provided with gnat, hoping= to find something similar to my construction. I think I saw an example of what you mean. To c= omplicate for the moment. Probably much easier to remove the limited. > This applies to an extended return statement. In your example, you are=20 > using a simple return statement, if you want to use an extended return,= =20 > you need to use that syntax. >=20 > The result subtype of your function is defined by a subtype_mark=20 > (Iterator), so 6.5(5.2/2) is saying that the declaration of the result=20 > object in the extended return must also be an Iterator, but you may=20 > optionally add further constraints on the declaration. In your case, you= =20 > need to add a discriminant constraint for the access to the List=20 > discriminant, since you want the result to have that value. >=20 > eg. >=20 > return Result (L) : Iterator do > null; > end return; Result(L): Iterator -- compiler not happy.=20 Result: Iterator(L) do -- works.=20 So I modified Iterator to private only and adapted the search function: function Search (L : access List; Element : Element_Type) return Iterat= or is It : Iterator (L); begin Start (It); while not Done (It) loop if Equals (It.This.Element, Element) then return Result : Iterator (L) do Result :=3D It; end return; end if; Next (It); end loop; return Result : Iterator (L) do It.This:=3D null; Result :=3D It;=20 end return; end Search; Is that correct or just garbage. At least it compiles but that doesn't mean= anything. Compiler is quite picky:=20 It.This:=3D null; Result :=3D It; That compiles but Result :=3D null; won't, expecting Iterator getting acces= s? Thanks for your patience Laurent