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 2002:ac8:4e50:: with SMTP id e16mr1958976qtw.149.1591777272781; Wed, 10 Jun 2020 01:21:12 -0700 (PDT) X-Received: by 2002:aca:4758:: with SMTP id u85mr1521205oia.175.1591777272483; Wed, 10 Jun 2020 01:21:12 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!tr3.eu1.usenetexpress.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 10 Jun 2020 01:21:12 -0700 (PDT) In-Reply-To: <2bbd5c7c-78da-4127-b85a-eeb3f9651456o@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=2a02:6d40:37c2:c301:441b:c0ae:113c:d142; posting-account=3Fg1FgoAAACfsmWScNfMD1tGFhR4DU0o NNTP-Posting-Host: 2a02:6d40:37c2:c301:441b:c0ae:113c:d142 References: <2bbd5c7c-78da-4127-b85a-eeb3f9651456o@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <3a31389d-d554-46f5-930e-495192b1fbcbo@googlegroups.com> Subject: Re: generic with function procedure From: Gilbert Gosseyn Injection-Date: Wed, 10 Jun 2020 08:21:12 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:59026 Date: 2020-06-10T01:21:12-07:00 List-Id: On Tuesday, June 9, 2020 at 6:44:13 PM UTC+2, Shark8 wrote: > On Friday, June 5, 2020 at 8:35:34 AM UTC-6, Gilbert Gosseyn wrote: > >=20 > > the message is: no visible subprogram matches the specification for "g" > > no visible subprogram matches the specificat= ion for "h" >=20 > Well, first, let's look at some generic code: > Generic > Type Element is private; > Type Index is (<>); > Type Vector is Array( Index range <> ) of Element; > Zero : Element; > with Function "+"( Left, Right : Element ) return Element is <>; > Function Generic_Sum( Input : Vector ) return Element; > Function Generic_Sum( Input : Vector ) return Element is > Return Result : Element :=3D Zero do > For Item of Input Loop > Result:=3D Result + Item; > End Loop; > End Return; > End Generic_Sum; >=20 > Now, if we say something like: > Package Example_1 is > Type X is private; > Type Y is range 1..7; > Type Vector is Array(Y range <>) of X; >=20 > Function "+"( Right : Vector ) return Element; > Default : Constant X; > Private > Function Sum is new Generic_Sum(X,Y,Vector, Zero =3D> Default, other= s =3D> <>); > Type X is range 0..15; -- 4-bits. > Function "+"( Right : Vector ) return Element > renames Sum; > Default : Constant X :=3D 0; > End Example_1; >=20 > ...doesn't work. Why? > Well, for one, the point where you're trying to instantiate Generic_Sum i= nto Sum, even though the parameter (X) matches the formal parameter, at thi= s point in the code the only thing we know is that it's a private type... i= t doesn't have a "+" function that it can see, and so it will tell you that= there's nothing to match with function "+". >=20 > Swapping the "function Sum is" and "type X is" lines would solve that pro= blem, but there *might* be another, similar one: the constant (Default) has= n't yet been assigned a value and so the instantiation might fail. (I'd hav= e to re-read the ARM,) >=20 > In your post the line "procedure nm is new denm(f=3D>f1,g=3D>g1,h=3D>h1);= " is analogous to the situation above, albeit slightly different: you're ex= plicitly specifying that subprograms "g1" and "h1" are to be respectively a= ssociated with parameters "g" and "h" -- this is all well and good, and the= compiler has caught two mistakes for you: > =E2=80=94 no visible subprogram matches the specification for "g" > =E2=80=94 no visible subprogram matches the specification for "h"=20 >=20 > So it's telling you that of all the functions "g1" that it sees at the po= int of instantiation, none match the generic's specification of "function g= (j : Integer; v : Real_Vector) return Real;" > (and the same for "h".) >=20 > Now, at this point the compiler cannot do anything more: this is the real= m where only the human programmer can tell what to do: > =E2=80=94 Is it a copy and paste-error creating the functions "g" and "h"= ? (Were they declared in the form of "f" which is "(v : Real_Vector) return= Real;" instead of "(j : Integer; v : Real_Vector) return Real;"?) > =E2=80=94 Did you perhaps mean to make the formal parameters of denm, "g"= and "h", to be "(v : Real_Vector) return Real;" instead of "(j : Integer; = v : Real_Vector) return Real;"? (Perhaps being interrupted while refactorin= g it, and it's stuck in a form intermediate between what you had and what y= ou want.) > =E2=80=94 Did you forget to make a "g1" and "h1"? Apparently the problem is solved when I make the parameter list for f, g, a= nd h the same. (it must be a well known fact when using more than one with.= However, I missed it). Thanks to all contributors.