From: Roland Illig <roland.illig@gmx.de>
Subject: Re: [newbie] simple(?) data structures
Date: Sun, 13 Jun 2004 05:13:11 +0200
Date: 2004-06-13T05:13:11+02:00 [thread overview]
Message-ID: <2j1v28Fs989jU1@uni-berlin.de> (raw)
In-Reply-To: <878yesgvw5.fsf@insalien.org>
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
next prev parent reply other threads:[~2004-06-13 3:13 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-12 22:23 [newbie] simple(?) data structures Roland Illig
2004-06-12 22:52 ` Frank
2004-06-13 0:10 ` Ludovic Brenta
2004-06-13 3:13 ` Roland Illig [this message]
2004-06-13 7:59 ` Marius Amado Alves
2004-06-13 11:56 ` Ludovic Brenta
2004-06-13 14:47 ` Stephen Leake
2004-06-13 18:24 ` Jeffrey Carter
2004-06-13 0:31 ` Jeffrey Carter
2004-06-13 1:26 ` tmoran
2004-06-13 2:47 ` tmoran
2004-06-13 3:53 ` Roland Illig
2004-06-13 10:12 ` Georg Bauhaus
2004-06-13 23:32 ` Robert I. Eachus
2004-06-14 12:29 ` Georg Bauhaus
2004-06-13 4:46 ` Steve
2004-06-13 4:59 ` tmoran
2004-06-13 17:58 ` Jeffrey Carter
2004-06-16 11:08 ` Roland Illig
2004-06-16 21:05 ` Georg Bauhaus
2004-06-16 23:23 ` Roland Illig
2004-06-17 0:44 ` Jeffrey Carter
2004-06-17 12:37 ` Hyman Rosen
2004-06-17 13:11 ` Björn Persson
2004-06-18 9:55 ` Ole-Hjalmar Kristensen
2004-06-18 11:03 ` Björn Persson
2004-06-18 12:04 ` Hyman Rosen
2004-06-22 8:11 ` Ole-Hjalmar Kristensen
2004-06-18 0:20 ` David Starner
2004-06-18 5:06 ` Hyman Rosen
2004-06-18 5:47 ` Martin Krischik
2004-06-18 7:30 ` Brian May
2004-06-18 14:21 ` Larry Kilgallen
2004-06-19 19:51 ` Robert I. Eachus
2004-06-18 15:04 ` Georg Bauhaus
2004-06-19 2:02 ` James Rogers
2004-06-18 9:51 ` Ole-Hjalmar Kristensen
2004-06-27 13:12 ` Jacob Sparre Andersen
2004-06-24 0:09 ` Matthew Heaney
2004-06-24 14:50 ` Nick Roberts
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox