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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,bed01d177eaef486 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.224.39.72 with SMTP id f8mr1459680qae.7.1343316918239; Thu, 26 Jul 2012 08:35:18 -0700 (PDT) Received: by 10.66.85.231 with SMTP id k7mr1821284paz.38.1343316918140; Thu, 26 Jul 2012 08:35:18 -0700 (PDT) Received: by 10.68.228.227 with SMTP id sl3mr398254pbc.5.1343314592382; Thu, 26 Jul 2012 07:56:32 -0700 (PDT) Path: a15ni113198934qag.0!nntp.google.com!q21no6960441qas.0!news-out.google.com!p10ni65138561pbh.1!nntp.google.com!u4no20839pbs.0!news-out.google.com!b9ni64917635pbl.0!nntp.google.com!border1.nntp.dca.giganews.com!novia!volia.net!news2.volia.net!feed-A.news.volia.net!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!newsfeed.straub-nv.de!news.swapon.de!news.glorb.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Keean Schupke Newsgroups: comp.lang.ada Subject: Re: Signature Package With Generic Proceedure Date: Sun, 22 Jul 2012 09:22:55 -0700 (PDT) Organization: http://groups.google.com Message-ID: <88734b25-68e5-42b2-89ea-0c0e3fc9fbc5@googlegroups.com> References: <045f7b44-2a4a-4292-80fd-0b6bc8ee3465@googlegroups.com> NNTP-Posting-Host: 82.44.19.199 Mime-Version: 1.0 X-Trace: posting.google.com 1342974176 15325 127.0.0.1 (22 Jul 2012 16:22:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 22 Jul 2012 16:22:56 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=82.44.19.199; posting-account=T5Z2vAoAAAB8ExE3yV3f56dVATtEMNcM User-Agent: G2/1.0 X-Received-Bytes: 4793 X-Original-Bytes: 4998 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-07-22T09:22:55-07:00 List-Id: On Saturday, 21 July 2012 23:22:36 UTC+1, Adam Beneschan wrote: > On Saturday, July 21, 2012 10:22:25 AM UTC-7, Keean Schupke wrote: > > If I have a package which defines a procedure like: > >=20 > >=20 > > generic > > with procedure Process(Set : in out Set_Type); > > procedure Update(Set : in out Set_Type); > >=20 > >=20 > > How do a declare a Signature package that includes this? > >=20 > >=20 > > generic > > with generic > > with procedure Process(Set : in out Set_Type); > > procedure Update(Set : in out Set_Type); > > package Set_Signature is end; > >=20 > >=20 > > Is not allowed. Is there some way to do this with nested packages? >=20 > There's no such thing as "with generic" in Ada. That is, t= here is no way to set things up so that you can instantiate a generic like = this: >=20 > package An_Instantiation is new A_Generic (G1); >=20 > where G1 is the name of a *generic* subprogram or package. Nor can I thi= nk of a reason why you'd want to. Perhaps if you gave us an example of= what you're trying to accomplish? >=20 > -- Adam Why would you want to? Easy... You use signature packages to decouple the i= mplementation from the interface, so that other packages can decide which i= mplementation to use. Lets say we have two disjoint-set implementations, an Eager_Disjointset and= a WUQPC_Disjointset. Both of these share a common interface, which we want= to enforce so we declare a separate signature package Disjointset_Signatur= e to describe this common interface. The algorithms that use Disjointset are written using=20 generic with package Disjointset is new Disjointset_Signature (<>); package X is begin So they can be compiled only 'with' the Disjointset_Signature package. The final code which uses the algorithm can choose which container implemen= tation to use by: package My_Disjointset is new Eager_Disjointset; use My_Disjointset; package My_Disjointset_Spec is new Disjointset_Signature( Set_Type =3D> My_Disjointset.Set_Type ); procedure My_Algorithm is new Algorithm( Disjointset_Spec =3D> My_Disjointset_Spec ); But another part of the code could use the same algorithm with a different = implementation of the container. The problem comes implementing a function to mutate (update in place) data = stored in the container. Maybe we want to implement: procedure Update( Set : in out Set_Type; Index : in Index_Type; Process : access procedure( Element : in out Element_Type ) ); But this is slow because the procedure has to be passed as an access and ca= nnot be inlined. So instead we try: generic with procedure Process( Element : in out Element_Type; ); procedure Update( Set : in out Set_Type; Index : in Set_Index ); This is good because 'Process' can be inlined, however how do we express th= is in the Signature package that represents the interface to these packages= ? In the code that uses this we want to instantiate the generic with the rele= vant Process procedure, without referencing which implementation of Disjoin= tset will eventually be used. procedure Algorithm(Set : in out Set_Type) is procedure My_Process(Element : in out Element_Type) ( ... ); My_Update is new Update(Process =3D> My_Process); begin for J of Set loop My_Update(Set, J); end loop; end Algorithm; Cheers, Keean.