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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.109.57.162.254.mobile.3.dk!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: FIFO Date: Sun, 17 Sep 2017 09:39:52 +0200 Organization: JSA Research & Innovation Message-ID: <87poap93jr.fsf@jacob-sparre.dk> References: <87wp4y8vkn.fsf@jacob-sparre.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: franka.jacob-sparre.dk; posting-host="109.57.162.254.mobile.3.dk:109.57.162.254"; logging-data="3662"; mail-complaints-to="news@jacob-sparre.dk" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:ievhLRCSohWc5VaT0QcxpRamJ0U= Xref: news.eternal-september.org comp.lang.ada:48162 Date: 2017-09-17T09:39:52+02:00 List-Id: Frank Buss wrote: > And everyone feel free to criticize my code, as I'm very new to > Ada. For example, I saw that when you want to package something > neatly, but it consists mainly of one type, then the package is named > plural of the type, like I did: "Ringbuffers" and "Ringbuffer" for the > type. Is this common practice? It is one of three common practices: 1) package Noun is subtype Parent is ...; type Instance is new Parent with ...; subtype Class is Instance'Class; 2) package Plural_Noun is type Noun is ...; 3) package ... is type Noun_Type is ...; The last of the three practices is explicitly frowned upon by the "Ada (95) Quality and Style Guide", while the first two are listed as suggested practices. > For testing I wrote a small program. How do Ada programmers usually > test their libraries and programs? For Java I often use JUnit. I usually use Ahven. There is also AUnit, but when I tried to use it, I found that the tool, which should make it easier to use than Ahven didn't work on my system. > generic > Size : Positive; > type Item is private; > package Ringbuffers is Another option is: generic type Index is mod <>; type Element is private; package Ring_Buffer is type Instance is tagged private; subtype Class is Instance'Class; procedure Write (Buffer : in out Instance; New_Item : in Element); function Read (Buffer : in out Instance) return Element; function Is_Empty (Buffer : Instance) return Boolean; private type Element_Array is array (Index) of Element with Volatile; -- I'm not sure this does what you want. type Instance is tagged record Head, Tail : Index := Index'First; Elements : Element_Array; end record with Volatile; -- I'm not sure this does what you want either. end Ring_Buffer; Notice that "Volatile" is a bit tricky. I'm not sure if that is what you need. Nor if it makes sense to declare both types volatile. Greetings, Jacob -- "In space, no-one can press CTRL-ALT-DEL" -- An Ada programmer