comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: Function definitions - with clarification
Date: Mon, 23 Jun 2014 09:26:57 -0700 (PDT)
Date: 2014-06-23T09:26:57-07:00	[thread overview]
Message-ID: <cfc26d50-7ab6-4a42-9ec6-33a42f63924d@googlegroups.com> (raw)
In-Reply-To: <f12eba4c-2757-4496-861b-101cb7e355d6@googlegroups.com>

On Sunday, June 22, 2014 4:34:09 AM UTC-7, montgrimpulo wrote:

> type Individual (P, Q, R) is record 
> X : x_array (0..P); 
> Y : y_array (0..Q); 
> Z : z_array (0..R); 
> end record; 

> -- type population is array (1 .. Popsize) of Individual; 
> -- gives: unconstrained element in array declaration 

If you are trying to set up an array of Individuals where the Individuals could all have different discriminants: you can't do that in Ada.  Sorry.  The reason is that to set up an array, the elements all have to be the same size, and an Individual(P=>3, Q=>5, R=>4) will have a different size than an Individual(P=>2, Q=>2, R=>1).  [That may not be true on all compilers.  But the language was designed so that it would work on compilers that do allocate different sizes for those different records.]

If this is what you want, you will have to start using access types.  I.e.

    type Individual_Acc is access Individual;
    type population is array (1 .. Popsize) of Individual_Acc;

Now, all the array elements are accesses (pointers), so they will have the same size.

If you want a Population where each Individual has the **same** discriminants, you could get it to work by putting discriminants on the array.  The problem is that you can't put discriminants on an array, but you can put them on a record containing the array:

    type Population (P, Q, R : Natural) is record
        Population_Data : array (1 .. Popsize) of Individual(P, Q, R);
    end record;

I haven't tested this but I *think* it will work.

                           -- Adam

  parent reply	other threads:[~2014-06-23 16:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-22 11:34 Function definitions - with clarification montgrimpulo
2014-06-22 12:04 ` Simon Clubley
2014-06-22 14:25 ` montgrimpulo
2014-06-22 15:30 ` Georg Bauhaus
2014-06-22 17:29 ` montgrimpulo
2014-06-22 17:45 ` Shark8
2014-06-22 18:03   ` montgrimpulo
2014-06-22 18:45     ` Simon Clubley
2014-06-22 19:28       ` montgrimpulo
2014-06-22 21:04         ` Simon Wright
2014-06-22 21:17       ` Jeffrey Carter
2014-06-22 19:55     ` Shark8
2014-06-23 16:26 ` Adam Beneschan [this message]
2014-06-29 15:31 ` cotswold
2014-06-29 19:20 ` montgrimpulo
2014-06-30  9:29   ` G.B.
2014-06-30 17:55     ` Shark8
2014-07-01  8:58       ` Georg Bauhaus
2014-07-04  6:45         ` J-P. Rosen
2014-06-30 13:23 ` montgrimpulo
replies disabled

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