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=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!postnews2.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: [newbie] simple(?) data structures Date: 23 Jun 2004 17:09:40 -0700 Organization: http://groups.google.com Message-ID: <1ec946d1.0406231609.11a051cb@posting.google.com> References: <2j1e30Fsrg8vU1@uni-berlin.de> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1088035781 31425 127.0.0.1 (24 Jun 2004 00:09:41 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 24 Jun 2004 00:09:41 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:1840 Date: 2004-06-23T17:09:40-07:00 List-Id: Roland Illig wrote in message news:<2j1e30Fsrg8vU1@uni-berlin.de>... > Hi, > > I'm doing my first steps with Ada. I tried to model a Go board and > failed. In Java/C++, I would do it like this: > > enum Stone { Empty, Black, White }; > > class Go_Board { > private Stone[][] data; > > public Go_Board(int size) { > data = new Stone[size][size]; > } > public int getWidth() { > return data[0].length; > } > public int getHeight() { > return data.length; > } > public Stone getStone(int x, int y) { > return data[y][x]; > } > } > /* EOF */ > > How can I do this in Ada? I already tried something with packages and > generics, but that did not look nice. But I want it to look nice and Adaish. You didn't need generics for the Java program, so therefore you don't need them for the Ada program, either: package Go_Boards is type Board_Type (Size : Positive) is private; type Stone_Type is (Empty, Black, White); function Stone (Board : Board_Type) return Stone_Type; --function Width (B : BT) return Positive; --same as B.Size? private type Data_Type is array (Positive range <>, Positive range <>) of Stone_Type; type Board_Type (Size : Positive) is record Data : Data_Type (1 .. Size, 1 .. Size); end record; end Go_Boards; I haven't tried compiling this, but I think it should work.