comp.lang.ada
 help / color / mirror / Atom feed
From: John Smith <yoursurrogategod@gmail.com>
Subject: Re: Generating a random number, not sure why I'm getting this error
Date: Sun, 15 Nov 2015 18:53:20 -0800 (PST)
Date: 2015-11-15T18:53:20-08:00	[thread overview]
Message-ID: <d0ef6159-a8d2-4b2f-8ceb-1b1f9383b736@googlegroups.com> (raw)
In-Reply-To: <n2bet4$595$1@dont-email.me>

On Sunday, November 15, 2015 at 9:29:06 PM UTC-5, Jeffrey R. Carter wrote:
> On 11/15/2015 06:25 PM, John Smith wrote:
> > 
> > with Ada.Numerics.Discrete_Random; ... 
> > Ada.Numerics.Discrete_Random.Reset(Ada.Numerics.Discrete_Random.Generator);
> 
> Generator is a type, not something you can pass to a subprogram. What would you
> expect a call to Random to return?
> 
> > And this is the error that I get:
> > 
> > :13:15: invalid prefix in selected component "Ada.Numerics.Discrete_Random"
> > -- refers to the first Ada.Numerics.Discrete_Random...
> 
> Not a great error msg.
> 
> Discrete_Random is not a package: it's a generic package. You can consider a
> generic like a template for a package or subprogram. You create a package or
> subprogram from the generic through what Ada calls instantiation. When you
> instantiate Discrete_Random, you supply a discrete subtype to fill in for
> Result_Subtype; Random returns a value of this subtype.
> 
> So, for example,
> 
> package Random is new Ada.Numerics.Discrete_Random (Result_Subtype => Character;
> -- Random is the name of the pkg created by the instantiation
> 
> Gen : Random.Generator;
> C   : Character;
> 
> Random.Reset (Gen => Gen);
> C := Random.Random (Gen);
> 
> -- 
> Jeff Carter
> "Apart from the sanitation, the medicine, education, wine,
> public order, irrigation, roads, the fresh water system,
> and public health, what have the Romans ever done for us?"
> Monty Python's Life of Brian
> 80

Ok, that's what I was missing.  I didn't realize that that was how generic packages should be used.  I figured that they should be used just like any other package.

Thank you.

  reply	other threads:[~2015-11-16  2:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-16  1:25 Generating a random number, not sure why I'm getting this error John Smith
2015-11-16  2:29 ` Jeffrey R. Carter
2015-11-16  2:53   ` John Smith [this message]
2015-11-16  8:51     ` Simon Wright
replies disabled

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