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 10.36.237.6 with SMTP id r6mr4519195ith.12.1478121068975; Wed, 02 Nov 2016 14:11:08 -0700 (PDT) X-Received: by 10.157.34.104 with SMTP id o95mr653204ota.6.1478121068921; Wed, 02 Nov 2016 14:11:08 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!p16no281942qta.1!news-out.google.com!z32ni323qtc.1!nntp.google.com!n6no282311qtd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 2 Nov 2016 14:11:08 -0700 (PDT) In-Reply-To: <2ca2899f-766b-49d8-ac19-63e474994402@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=67.0.194.200; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 67.0.194.200 References: <2ca2899f-766b-49d8-ac19-63e474994402@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0e4896f7-9d27-48e0-b9cd-8e2b1f0b267e@googlegroups.com> Subject: Re: Ada language help From: Shark8 Injection-Date: Wed, 02 Nov 2016 21:11:08 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 5199 X-Received-Body-CRC: 25082861 Xref: news.eternal-september.org comp.lang.ada:32223 Date: 2016-11-02T14:11:08-07:00 List-Id: Jeffrey is right, you should start out writing the generic's interface when= you're doing this; however, if you have no Ada experience, then we should = probably go over types and record-discriminants before actually doing the p= roject: The simplest type is that which is completely public, arguably [re-]definin= g a new type from existing types is easier than a completely new type (beca= use they inherit operations), but here's an example of a few completely pub= lic types: Type Percent is range 0..100; Type Word is new Integer; Type Point is record X, Y : Integer; end record; All very simple. Well, let's change things up a bit and throw in discriminants -- we can re= write the type Point as the following: Type Point(X, Y : integer) is null record; This defines point as an "empty record" with two discriminants -- discrimin= ants being essentially constant fields -- and this alters how it can be use= d: * You CANNOT define an unconstrained variable/constant, so no X : Point; --= ... * You CANNOT change the discriminant's values. * ANY variable constrained by initialization MUST obey those constraints; t= his is wht if you say something like EX : STRING :=3D "Dave"; can't later b= e assigned with EX :=3D "Bob"; -- The length of "Dave" (four characters) co= nstrains EX and "Bob" has only a length of three. (You *could* do EX:=3D "M= ike" though.) * Discriminants can often be thought of like parameters; though this gets a= bit cloudy w/ access discriminants. (You don't need access discriminants f= or this, so I won't cover them.) Discriminants can also be used to "dynamically bind/define" records; as an = example: Type Level is ( LOW, MEDIUM, HIGH ); Type Alert( Priority : Level; Length : Natural ) is record Message : String(1..Length); end record; This defines an "alert", giving both message-length and priority as paramet= ers -- so, given the attributes listed above, a message defined this way ca= nnot have a length-data mismatch -- which precludes the whole Heartbleed bu= g. Having covered public types and discriminants, let's cover private types --= private types are those which have an implementation that [generally] isn'= t viewable/accessible to the rest of your program. (The exception is in chi= ld units which can "see" into their parent's private area.) -- So here's an= example of a private-type: Package Example is Type Useless is private; Private -- Cyclic Counter type. Type Useless is range 1..4; End Example; This type lives up to its name, "Useless", because there's no way that the = rest of your programs can manipulate such a variable -- you need to define = the operations yourself: Package Example is Type Counter is private; Procedure Inc( X : in out Counter ); Function Initialize return Counter; Function Get( X : Counter ) return Positive; Private -- Cyclic Counter type. Type Counter is range 1..4; Function Initialize return Counter is (Counter'First); End Example; Package Body Example is Procedure Inc( X : in out Counter ) is begin X:=3D (if X =3D Counter'Last then Counter'First else X+1); end Inc; Function Get( X : Counter ) return Positive is begin Return Positive( X ); -- Manually convert. end Get; End Example; And now you have an interface for your type "Counter" -- writing the generi= c-interface is first thinking in terms of the interface, the parameters for= the type are what the generic can assume about the type, so if you write a= generic parameter as a private type the generic can only treat it as a pri= vate type (there is no 'specialization' as in C++) because you are writing = in a generic manner. So, that's about all the pieces you really need to know/understand to get t= his homework done. -- Hope that helps.