comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: random number generation
Date: Fri, 26 Sep 2003 21:44:13 GMT
Date: 2003-09-26T21:44:13+00:00	[thread overview]
Message-ID: <Nq2db.591515$Ho3.113457@sccrnsc03> (raw)
In-Reply-To: vn94lrbrcr6m38@corp.supernews.com

> the problem is I get errors such as
> mazecreate.adb:18:04: statement not allowed in declarative part
    The compiler is trying to help you.
It's telling you that line 18 has a statement, but it's in a
declarative part, ie, a part where there are supposed to be just
declarations.  Looking at line 18, I see
    X:= Generator_Options.Random(A_Generator);
which is an assignment statement, not a declaration.
  It's also the case that Ada programs are normally readable from
top to bottom.  Your's has
    A_Generator : Generate_Options.Generator;
before you've declared what "Generate_Options" is, so you need
to move
    A_Generator : Generate_Options.Generator;
after
    package Generate_Options is new
       Ada.Numerics.Discrete_Random(Options);
Of course you will also need to tell the compiler what
Ada.Numerics.Discrete_Random is, by putting it in a "with" statement
at the beginning of your program.

  What is X?  A general integer, which can legitimately be negative or
very large, and which can be added and multiplied by any other Integer?
Or is X a code, say for card suits, or one of four symbols in maze, where
adding two of them together or multiplying by -3, would make no sense.
If it's a code, then you need
  X : Options;
(after Options has been declared) instead of
  X : Integer;
If X is a general purpose Integer, then type Options should be a subtype
of Integer, not a full-fledged type of its own, ie, it should be:
  subtype Options is Integer range 1 .. 4;
  I notice your program does not actually use X anywhere.  I presume
that's because you just haven't gotten to coding that yet.
  A couple other notes:  The Is_Open test right after Create is not
really necessary.  Either the file is open, or if there was a problem
creating such a file Create would have raised an exception and you
won't be executing the "if Is_Open" code.
  Having variables named "spot" and "spott" means that when you mistype one
as the other the compiler won't be able to warn you, and you'll wonder why
your program doesn't work right.  Better to choose names so a simple typo
will do something detectable by the compiler as an error.



  parent reply	other threads:[~2003-09-26 21:44 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-26  7:00 random number generation Andrew
2003-09-26  7:35 ` tmoran
2003-09-26 17:58   ` Andrew
2003-09-26 19:25   ` Andrew
2003-09-26 19:35     ` chris
2003-09-26 21:44     ` tmoran [this message]
2003-09-27  1:40     ` Robert I. Eachus
2003-09-27  4:48       ` Andrew
  -- strict thread matches above, loose matches on Subject: below --
2010-12-30 10:43 Random " Mart van de Wege
2010-12-30 10:54 ` Thomas Løcke
2010-12-30 12:11   ` Mart van de Wege
2010-12-30 11:34 ` Niklas Holsti
2010-12-30 11:53   ` Georg Bauhaus
2010-12-30 12:25     ` Mart van de Wege
2010-12-30 15:29       ` Georg Bauhaus
2010-12-30 15:37         ` Mart van de Wege
2010-12-30 11:51 ` Brian Drummond
2010-12-30 12:16   ` Mart van de Wege
2010-12-30 13:04 ` Dmitry A. Kazakov
2010-12-30 13:22   ` Niklas Holsti
2010-12-30 13:39     ` Dmitry A. Kazakov
2010-12-30 13:30   ` Mart van de Wege
2010-12-31  3:14 ` Gene
2010-07-13 12:45 tonyg
2010-07-13 12:50 ` Jacob Sparre Andersen
2010-07-13 12:58 ` Dmitry A. Kazakov
2010-07-13 13:17 ` Thomas Løcke
2010-07-13 16:07 ` Jeffrey R. Carter
2010-07-13 20:33   ` John B. Matthews
2010-07-13 23:02     ` Jeffrey R. Carter
2010-07-14  4:42       ` John B. Matthews
2010-07-15 19:01         ` tonyg
2003-09-26  7:14 random " christoph.grein
1997-12-19  0:00 Mok-kong Shen
1998-01-02  0:00 ` Mok-kong Shen
1998-01-02  0:00   ` Robert Dewar
1996-10-13  0:00 Random Number Generation parker
1996-10-13  0:00 ` Robert Dewar
1996-10-14  0:00 ` Robert A Duff
1996-10-10  0:00  Dr J Parker
1996-10-10  0:00  Dr J Parker
1996-10-12  0:00 ` Geert Bosch
1996-10-12  0:00 ` Keith Thompson
1996-10-02  0:00  Dr J Parker
1996-10-03  0:00 ` Mats Weber
1996-10-07  0:00 ` Geert Bosch
1996-09-23  0:00 Nigel J. Tracey
1996-09-23  0:00 ` Tucker Taft
1996-10-02  0:00   ` Nigel J. Tracey
1996-10-02  0:00   ` Robert I. Eachus
1996-10-03  0:00   ` Nigel J. Tracey
1996-09-25  0:00 ` James_Rogers
1996-09-26  0:00   ` Dale Stanbrough
1996-10-01  0:00   ` Robert I. Eachus
1996-09-30  0:00 `  Dr J Parker
1996-10-01  0:00   ` Tucker Taft
1996-10-01  0:00     ` Keith Thompson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox