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,ffef1fd08e45df0c X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!b5g2000pri.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: using put procedure with a generic package Date: Thu, 8 May 2008 08:54:56 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <151bc418-a6e4-47ef-ab7f-5b93a3cedb58@r66g2000hsg.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1210262096 12213 127.0.0.1 (8 May 2008 15:54:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 8 May 2008 15:54:56 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b5g2000pri.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:5752 Date: 2008-05-08T08:54:56-07:00 List-Id: On May 7, 9:48 pm, "ophir.gef...@gmail.com" wrote: > On May 8, 7:09 am, "Jeffrey R. Carter" > > > > wrote: > > ophir.gef...@gmail.com wrote: > > > > * queues.ads: > > > with Ada.Text_IO; > > > generic > > > type Item is private; > > > with procedure Item_Put(The_Item : in Item); > > > Item_Put has exactly one parameter. > Hi > Thanks for the quick reply > > The problem is that the package needs to know how to handle most non- > limited types like Integer, String, Client, Plane, Book, Document, ... > The Put procedure in any of those might and should be different from > Put Integer. > > And I don't want to force the package user to declare a special Put > procedure with only one var. I think you should anyway, even if you think you don't want to. The generic is defined correctly; the generic formal subprogram reflects exactly what you need---an output routine that takes one parameter of type Item. In most cases, *somebody* is going to have to define a routine like that, somewhere. And if the package that defines, say, Document, doesn't provide a routine with exactly that profile (maybe the only Document output routines take page-dimension parameters), then whoever instantiates your generic is going to have to write a wrapper routine anyway. It's pretty common in my experience to have to write small routines like this for generic instantiation purposes, and I don't see that changing until they decide to add something like Lambda expressions to Ada, which I don't think will be happening soon. In fact, if the Put routines of Integer_IO didn't have default parameters (so that every time you called Put you would have to explicitly specify the Width and Base), it would seem normal, and not particularly burdensome, to write a one-parameter wrapper routine in order to instantiate the generic. I think only reason there's an issue, and that you "don't want to" make the users declare "special" Put routines, is that Put *looks* like it has just one parameter the way it's normally used. But since it doesn't, you're getting this error which is surprising, and that makes it seem like users are being forced to do something they shouldn't have to do. Probably, the solution is for the compiler to detect this case and display a more helpful error message, but other than that I don't think this is a problem. -- Adam