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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3404439c05a9ac3 X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: Generic package array parameter Date: 1999/11/12 Message-ID: <382c7b29_1@news1.prserv.net>#1/1 X-Deja-AN: 547887240 Content-transfer-encoding: 7bit References: <382255CE.F5CB679A@erols.com> Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 12 Nov 1999 20:40:09 GMT, 32.101.8.130 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada Date: 1999-11-12T00:00:00+00:00 List-Id: In article , Mario Amado Alves wrote: > generic > type X is (<>); > type Y is (<>); > type Table_Type is array(X, Y) of X; > Table: Table_Type; > package Foo is > ... > > which of course works, but is odd, and requires an equally odd > instantiation: > > type My_X is ...; > type My_Y is ...; > type My_Table_Type is array(My_X, My_Y) of My_X; > My_Table: My_Table_Type := (...); > package My_Foo is new Foo(My_X, My_Y, My_Table_Type, My_Table); > ... There is nothing odd about this instantiation. The only thing odd here is that you would find it odd! Your generic formal region has 3 formal types and 1 formal object, and you supply 3 actual types and 1 actual object. What else did you expect you'd have to do? If you call a subprogram that has 4 formal parameters, then you expect to call it with 4 actual parameters. What else is new? > This works, but is ugly and stupid. I'm sorry to hear that. > Is there a smart way to rewrite it? Do you need to import the type and the object as generic formals? generic type XT is (<>); type YT is (<>); type ZT is private; package GP is type Array_Type is array (XT, YT) of ZT; Table : Array_Type; ... end GP; Do you need to import index types? What's wrong with Positive? generic type ZT is private; Max_X : in Positive; Max_Y : in Positive; package GP is type Array_Type is array (Positive range <>, Positive range <>) of ZT; Table : Array_Type (1 .. Max_X, 1 .. Max_Y); ... end GP; If named access types offend you, then just declare your table with an anonymous type: generic ... package GP is Table : array (1 .. Max_X, 1 .. Max_Y) of ZT; end GP; > (I feel I am again on the verge of giving up the Ada generic programming > idiom. What is this Ada thing with anonymous array types?) Don't criticize what you don't understand. (Anonymous array types aren't allowed because, what would "=" mean for the type? What would ":=" mean for the type? function (L, R : ???) return Boolean; What's the type of the formal parameters of function "="? procedure ":=" (L : in out ???; R : in ???); What are the types on the LHS and on the RHS? Operations are always associated with a type. The type needs a name in order to associate an operation with the type. But if the array is anonymous, then you don't have a name, so you don't have the operation either...) -- Science is, foremost, a method of interrogating reality: proposing hypotheses that seem true and then testing them -- trying, almost perversely, to negate them, elevating only the handful that survive to the status of a theory. Creationism is a doctrine, whose adherents are interested only in seeking out data that support it. George Johnson, NY Times, 15 Aug 1999