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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,aa7f494bf30adbc7 X-Google-Attributes: gid103376,public Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Roland Illig Newsgroups: comp.lang.ada Subject: Re: [newbie] simple(?) data structures Date: Sun, 13 Jun 2004 05:13:11 +0200 Message-ID: <2j1v28Fs989jU1@uni-berlin.de> References: <2j1e30Fsrg8vU1@uni-berlin.de> <878yesgvw5.fsf@insalien.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 4xlxYpPhm2/miOI6p/FwBwIc/ASWnJfxUhXg49MimXd1091H0= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040528 Debian/1.6-7 X-Accept-Language: de-de, de, en-us, en In-Reply-To: <878yesgvw5.fsf@insalien.org> Xref: g2news1.google.com comp.lang.ada:1436 Date: 2004-06-13T05:13:11+02:00 List-Id: Ludovic Brenta wrote: > Cool, great attitude. Here is how I would do it, using generics like > you suggested: > > generic > Size : in Positive; > package Go_Board is > type Width is range 1 .. Size; > type Height is range 1 .. Size; > > type Stone is (Empty, Black, White); > > function Get_Stone (X : in Width; Y : in Height) return Stone; > procedure Set_Stone (X : in Width; Y : in Height; S : in Stone); > private > Board : array (Width, Height) of Stone; > end Go_Board; That looks cool to me. That's exactly as I wanted it. (Burden the compiler with all those range checking :)) > > Each instance of this package contains one board; thus you do not need > a constructor. To create an instance: > > with Ada.Text_IO; > with Go_Board; > procedure Test_Go_Board is > package The_Board is new Go_Board (Size => 10); > begin Many thanks for your detailed answer. Now I know what I forgot to say. The thing that makes the definition of the data structure that complicated is that I want to choose the size of the Go_Board at runtime and I want to pass that Go_Board to other subprograms. Is that possible with packages? -- function New_Board(The_Size : Integer) return Go_Board is -- package The_Board is new Go_Board (Size => The_Size); -- begin -- return The_Board; -- end New_Board; -- procedure Print_Board(Board : Go_Board) is -- begin -- null; -- end Print_Board; > (note that I avoided using "use Ada.Text_IO; use The_Board" because I > wanted to make things really obvious; but you may want to consider > using such use clauses if you think the code is too cluttered) I like that style. It's almost equal to my own. > HTH It did a lot. Thanks again. Roland