From: Shark8 <onewingedshark@gmail.com>
Subject: Re: generic with function procedure
Date: Tue, 9 Jun 2020 09:44:11 -0700 (PDT)
Date: 2020-06-09T09:44:11-07:00 [thread overview]
Message-ID: <2bbd5c7c-78da-4127-b85a-eeb3f9651456o@googlegroups.com> (raw)
In-Reply-To: <d10989b4-ed2f-47c8-8f95-4d2f0d9cdafdo@googlegroups.com>
On Friday, June 5, 2020 at 8:35:34 AM UTC-6, Gilbert Gosseyn wrote:
>
> the message is: no visible subprogram matches the specification for "g"
> no visible subprogram matches the specification for "h"
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 := Zero do
For Item of Input Loop
Result:= Result + Item;
End Loop;
End Return;
End Generic_Sum;
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;
Function "+"( Right : Vector ) return Element;
Default : Constant X;
Private
Function Sum is new Generic_Sum(X,Y,Vector, Zero => Default, others => <>);
Type X is range 0..15; -- 4-bits.
Function "+"( Right : Vector ) return Element
renames Sum;
Default : Constant X := 0;
End Example_1;
...doesn't work. Why?
Well, for one, the point where you're trying to instantiate Generic_Sum into Sum, even though the parameter (X) matches the formal parameter, at this point in the code the only thing we know is that it's a private type... it doesn't have a "+" function that it can see, and so it will tell you that there's nothing to match with function "+".
Swapping the "function Sum is" and "type X is" lines would solve that problem, but there *might* be another, similar one: the constant (Default) hasn't yet been assigned a value and so the instantiation might fail. (I'd have to re-read the ARM,)
In your post the line "procedure nm is new denm(f=>f1,g=>g1,h=>h1);" is analogous to the situation above, albeit slightly different: you're explicitly specifying that subprograms "g1" and "h1" are to be respectively associated with parameters "g" and "h" -- this is all well and good, and the compiler has caught two mistakes for you:
— no visible subprogram matches the specification for "g"
— no visible subprogram matches the specification for "h"
So it's telling you that of all the functions "g1" that it sees at the point of instantiation, none match the generic's specification of "function g(j : Integer; v : Real_Vector) return Real;"
(and the same for "h".)
Now, at this point the compiler cannot do anything more: this is the realm where only the human programmer can tell what to do:
— 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;"?)
— 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 refactoring it, and it's stuck in a form intermediate between what you had and what you want.)
— Did you forget to make a "g1" and "h1"?
next prev parent reply other threads:[~2020-06-09 16:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-05 14:35 generic with function procedure Gilbert Gosseyn
2020-06-05 14:52 ` gautier_niouzes
2020-06-05 15:45 ` Gilbert Gosseyn
2020-06-05 15:59 ` Dmitry A. Kazakov
2020-06-05 16:09 ` Anh Vo
2020-06-05 20:28 ` Jeffrey R. Carter
2020-06-09 16:44 ` Shark8 [this message]
2020-06-10 8:21 ` Gilbert Gosseyn
2020-06-10 8:45 ` AdaMagica
2020-06-12 14:29 ` Shark8
2020-06-12 16:45 ` Simon Wright
2020-06-12 18:49 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox