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,9677a3433b89e25b X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: attributes in generic procedure Date: 1999/11/21 Message-ID: <38380fdb_4@news1.prserv.net>#1/1 X-Deja-AN: 551272680 Content-transfer-encoding: 7bit References: <818esd$t6l$1@nnrp1.deja.com> Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 21 Nov 1999 15:29:31 GMT, 32.101.8.48 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada Date: 1999-11-21T00:00:00+00:00 List-Id: In article <818esd$t6l$1@nnrp1.deja.com> , daelen@my-deja.com wrote: > I would like to create a generic procedure as shown below which will only be > used for scalar types. Does anybody have a hint how to accomplish this? The issue is that there are different classes of scalar type, and generic formal types differentiate the classes: generic type Integer_Type is range <>; type Enum_Or_Int_Type is (<>); type Float_Type is digits <>; type Fixed_Type is delta <>; type Mod_Type is mod <>; > generic > type A_Type is private; > procedure Update (Par : in out A_Type; Value : String); It looks like you need First, Last, Pred, Succ. Import the type as private (like you already have), but also import constants and operations on that type: generic type T is private; First : in T; Last : in T; with function Pred (O : T) return T is <>; with function Succ (O : T) return T is <>; with function Value (S : String) return T is <>; procedure Generic_Update (O : in out T; Image : in String); Now, when a client instantiates the generic, he supplies the attribute functions defined for the type as generic actuals: function Update is new Generic_Update (T => Integer, First => Integer'First, Last => Integer'Last, Pred => Integer'Pred, ...); This will work for any scalar type. > procedure Update (Par : in out A_Type; Value : String) is > begin > if Value = "+" then > if Par = A_Type'Last then > Par := A_Type'First; > else > Par := A_Type'Succ (Par); > end if; For example: if Value = "+" then if Par = Last then Par := First; else Par := Succ (Par); end if; -- Yeah, well, no one was present when the dinosaurs lived, so I guess their presence in the fossil record is "only a theory." No one was present when the Grand Canyon was formed either, or the creation of the solar system, or, or, or. Of course evolution is "only a theory." What else would it be as a scientific concept? Skeptic magazine publisher Micheal Shermer, commenting on the recent decision by the Oklahoma board of education to include a disclaimer on school science textbooks warning that evolution is "only a theory." Skeptic web page: http://www.skeptic.com/