comp.lang.ada
 help / color / mirror / Atom feed
* Function definitions
@ 2014-06-20 15:18 montgrimpulo
  2014-06-20 15:44 ` Adam Beneschan
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: montgrimpulo @ 2014-06-20 15:18 UTC (permalink / raw)


Hi,

What would be an answer to the following question:

There are three files : search.ads, search.adb, main_search.adb

In search.ads two functions are defined:  function F and function G, like

function F (V : Individual) return Long_Float; and
function G(M : Natural; V : Individual) return Long_Float;

V is defined as a Record containing several unconstrained arrays.

In search.adb there are several procedures programmed using the functions F and G defined in search.ads.

The general search function (defined in search.adb) is called in main_search.adb. As I want to define  the internal statements of F and G, and other paramenters, (eg. concerning the
size of the arrays in V), only in main_search.adb, I don't know how to define F and G in search.ads / search.adb, as their body is claimed to be missing in search.adb.

Would a possible solution use an access type for the functions F and G ?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 15:18 Function definitions montgrimpulo
@ 2014-06-20 15:44 ` Adam Beneschan
  2014-06-20 16:22 ` montgrimpulo
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 18+ messages in thread
From: Adam Beneschan @ 2014-06-20 15:44 UTC (permalink / raw)


On Friday, June 20, 2014 8:18:25 AM UTC-7, montgrimpulo wrote:
> Hi,
> 
> What would be an answer to the following question:
> 
> There are three files : search.ads, search.adb, main_search.adb
> 
> In search.ads two functions are defined:  function F and function G, like
> 
> function F (V : Individual) return Long_Float; and
> function G(M : Natural; V : Individual) return Long_Float;
> 
> V is defined as a Record containing several unconstrained arrays.

It's kind of hard to tell what's going on when you try to describe your program in English instead of just showing us code.  

I don't think it's possible to define a record containing unconstrained arrays; a record component that has an array type has to be constrained by something, possibly a record discriminant.  

However, I can't answer anything else since I really don't understand what you're trying to do.  Please post some code.

                                -- Adam


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 15:18 Function definitions montgrimpulo
  2014-06-20 15:44 ` Adam Beneschan
@ 2014-06-20 16:22 ` montgrimpulo
  2014-06-20 16:43   ` Adam Beneschan
                     ` (2 more replies)
  2014-06-20 17:39 ` montgrimpulo
                   ` (2 subsequent siblings)
  4 siblings, 3 replies; 18+ messages in thread
From: montgrimpulo @ 2014-06-20 16:22 UTC (permalink / raw)


My modified question:

Hi,
What would be an answer to the following question:
There are three files : search.ads, search.adb, main_search.adb.
 
 In search.ads two functions are defined:  function F and function G, as
 
function F (V : Individual) return Long_Float; and
 
function G(M : Natural; V : Individual) return Long_Float;
 
Individual is defined as a Record containing several arrays
with a size determined by variables, eg . 

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

In search.adb there are several procedures using the functions F and G defined in search.ads.

The general search procedure g_search (P, Q, R) (defined in search.adb) is called in main_search.adb. 

As I want to define  the internal statements of F and G, and other paramenters, (eg. P,Q,R), only in file main_search.adb, I don't know how to define F and G in search.ads / search.adb, as their body is claimed to be missing in search.adb.

I hope that description is sufficient to answer my question on how to define F and G, so that I can use
the general search procedure g_search with many different versions of F and G ?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 16:22 ` montgrimpulo
@ 2014-06-20 16:43   ` Adam Beneschan
  2014-06-20 16:52     ` Simon Clubley
  2014-06-20 16:43   ` Simon Clubley
  2014-06-22  6:59   ` Shark8
  2 siblings, 1 reply; 18+ messages in thread
From: Adam Beneschan @ 2014-06-20 16:43 UTC (permalink / raw)


On Friday, June 20, 2014 9:22:30 AM UTC-7, montgrimpulo wrote:
> My modified question:
> 
> Hi,
> 
> What would be an answer to the following question:
> There are three files : search.ads, search.adb, main_search.adb.
> 
>  In search.ads two functions are defined:  function F and function G, as
>  
> function F (V : Individual) return Long_Float; and
> function G(M : Natural; V : Individual) return Long_Float;

> 
> Individual is defined as a Record containing several arrays
> with a size determined by variables, eg . 
> 
> type Individual is record
>  X : x_array (0 .. P);
>  Y : y_array (0 .. Q);
>  Z : z_array (0 .. R);
> end record;
>
> In search.adb there are several procedures using the functions F and G defined in search.ads.
> 
> The general search procedure g_search (P, Q, R) (defined in search.adb) is called in main_search.adb. 
> 
> As I want to define  the internal statements of F and G, and other paramenters, (eg. P,Q,R), only in file main_search.adb, I don't know how to define F and G in search.ads / search.adb, as their body is claimed to be missing in search.adb.
> 
> I hope that description is sufficient to answer my question on how to define F and G, so that I can use
> the general search procedure g_search with many different versions of F and G ?

I apologize, but I still cannot figure out what you are asking.  My problem is that you're using phrases that don't seem to have any clear connection with Ada concepts.  What do you mean by "many different versions of F and G"?  If you define a procedure, you're defining only one procedure; you can't normally have many different versions of the same procedure.  Are you trying to define an access-to-procedure type that can be used with a number of different search procedures?  Are you trying to use a generic?  Why do you want one function definition but many versions?  What are you planning on doing with the definition.

It looks like you have some code that isn't compiling.  I would suggest you post the *entire* code that you have so far.  Even if it's not proper Ada, it might show us what you're trying to accomplish.  Your description is not sufficient, and you probably cannot make it sufficient by just trying to use more words to describe it.  Sorry.

                                -- Adam

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 16:22 ` montgrimpulo
  2014-06-20 16:43   ` Adam Beneschan
@ 2014-06-20 16:43   ` Simon Clubley
  2014-06-22  6:59   ` Shark8
  2 siblings, 0 replies; 18+ messages in thread
From: Simon Clubley @ 2014-06-20 16:43 UTC (permalink / raw)


On 2014-06-20, montgrimpulo <aghte@hotlinemail.com> wrote:
>
> Hi,
> What would be an answer to the following question:
> There are three files : search.ads, search.adb, main_search.adb.
>  
>  In search.ads two functions are defined:  function F and function G, as
>  
> function F (V : Individual) return Long_Float; and
>  
> function G(M : Natural; V : Individual) return Long_Float;
>  
> Individual is defined as a Record containing several arrays
> with a size determined by variables, eg . 
>
> type Individual is record
>  X : x_array (0 .. P);
>  Y : y_array (0 .. Q);
>  Z : z_array (0 .. R);
> end record;
>
> In search.adb there are several procedures using the functions F and G
> defined in search.ads.
>
> The general search procedure g_search (P, Q, R) (defined in search.adb) is
> called in main_search.adb. 
>
> As I want to define  the internal statements of F and G, and other
> paramenters, (eg. P,Q,R), only in file main_search.adb, I don't know how to
> define F and G in search.ads / search.adb, as their body is claimed to be
> missing in search.adb.

It sounds like you have the spec for F and G in search.ads (which is
probably correct) but instead of placing the body in search.adb, you
want to place it in an unrelated main_search.adb.

If so, that's wrong; the body belongs in search.adb. You then "with",
in main_search.adb, the "search" package and reference it from
main_search.adb.

If you have attempted to place the body for F and G in search.adb and
failed, we need to see example code _and_ the _exact_ error messages.

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 16:43   ` Adam Beneschan
@ 2014-06-20 16:52     ` Simon Clubley
  2014-06-20 17:05       ` Adam Beneschan
  0 siblings, 1 reply; 18+ messages in thread
From: Simon Clubley @ 2014-06-20 16:52 UTC (permalink / raw)


On 2014-06-20, Adam Beneschan <adambeneschan@gmail.com> wrote:
>
> I apologize, but I still cannot figure out what you are asking.  My problem
> is that you're using phrases that don't seem to have any clear connection with
> Ada concepts.  What do you mean by "many different versions of F and G"?  If
> you define a procedure, you're defining only one procedure; you can't normally
> have many different versions of the same procedure.  Are you trying to define
> an access-to-procedure type that can be used with a number of different search
> procedures?  Are you trying to use a generic?  Why do you want one function
> definition but many versions?  What are you planning on doing with the
> definition.
>

I have a strong suspicion that what he's looking for are discriminated
records.

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 16:52     ` Simon Clubley
@ 2014-06-20 17:05       ` Adam Beneschan
  0 siblings, 0 replies; 18+ messages in thread
From: Adam Beneschan @ 2014-06-20 17:05 UTC (permalink / raw)


On Friday, June 20, 2014 9:52:29 AM UTC-7, Simon Clubley wrote:

> I have a strong suspicion that what he's looking for are discriminated
> records.
>
> Simon.

It kind of looks like that, but possibly not.  He may be looking for something involving generics.  I don't want to speculate until we have more information.

                                 -- Adam


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 15:18 Function definitions montgrimpulo
  2014-06-20 15:44 ` Adam Beneschan
  2014-06-20 16:22 ` montgrimpulo
@ 2014-06-20 17:39 ` montgrimpulo
  2014-06-20 18:19   ` Adam Beneschan
  2014-06-20 20:39   ` Robert A Duff
  2014-06-21 12:27 ` montgrimpulo
  2014-06-21 13:40 ` montgrimpulo
  4 siblings, 2 replies; 18+ messages in thread
From: montgrimpulo @ 2014-06-20 17:39 UTC (permalink / raw)


Here is some code:

File search.ads:

package search is

type x_array is array (positive range <>) of Float;
type y_array is array (positive range <>) of Integer;
type z_array is array (positive range <>) of Boolean;

P,Q,R : Natural;

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

function F (V : Individual) return Float;
function G (M : Positive; V : Individual) return Float;

procedure g_search ( P,Q,R : Natural);

...

procedure p1;
procedure p2;

...
end search;

File search.adb

package body search is

V : Individual;

procedure p1 is
FV : Float;
...
begin
...
FV := F(V);
...
end p1;

procedure p2 is
GMV : Float;
M : Positive;
...
begin
...
GMV := G(M,V);
end p2;

procedure g_search (P,Q,R : Natural) is
...
begin
p1;
p2;
...
end g_search;

end search;

File main_search.adb

with search; use search;

procedure main_search is

P := 1;
Q := 1;
R := 1;
 
V : Individual;

function F (V : Individual) return  Float is
begin
return Float(V.X(P));
end F;

function G (M : Individual) return Float is
begin
return Float(V.X(M));
end G;

begin
g_search(P,Q,R);
end main_search;

This is in principle what I want to set up and run, while I want to be flexible in defining F and G and other parameters, without having to modify the files search.ads and search.adb. 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 17:39 ` montgrimpulo
@ 2014-06-20 18:19   ` Adam Beneschan
  2014-06-20 18:20     ` Adam Beneschan
                       ` (2 more replies)
  2014-06-20 20:39   ` Robert A Duff
  1 sibling, 3 replies; 18+ messages in thread
From: Adam Beneschan @ 2014-06-20 18:19 UTC (permalink / raw)


On Friday, June 20, 2014 10:39:37 AM UTC-7, montgrimpulo wrote:
> Here is some code:

Thank you, it does make things a lot clearer.

First of all, if you want the bounds of Individual to be flexible, you'll need to make Individual a discriminant record:


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



This in effect puts "parameters" on the record.  The way you tried it did not use parameters; it used variables.  

    P,Q,R : Natural; 

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

What that does is to use whatever values P, Q, and R happened to have at the time the program reached the type declaration.  Since those variables were uninitialized, they would be garbage, but those garbage values would be used for the array bounds.  And changing P, Q, and R later, or redefining other variables named P, Q, and R, would not have helped.  The arrays in Individual would have those array bounds forever.  That's why you need to tell Ada that you are "parameterizing" the record by putting discriminants on them.  

Then, later, when you declare a variable of that type:

    V : Individual;  -- wrong

you have to specify the values of P, Q, and R:

    V : Individual (1, 1, 1);
    V : Individual (P => 1, Q => 1, R => 1);  -- better

The other thing is that instead of declaring F and G in search.ads as separate functions, you need to make them parameters of g_search.  You can do this with a generic, or with an access-to-procedure:

    generic
       with function F (V : Individual) return Float; 
       with function G (M : Positive; V : Individual) return Float; 
    procedure g_search; 

F and G are generic parameters.  I don't know if you want P, Q, and R to be parameters of g_search or not, since it still isn't clear what you want.  If g_search is supposed to search one of these records, you'll need to give it a record as a parameter:

    generic
       with function F (V : Individual) return Float; 
       with function G (M : Positive; V : Individual) return Float; 
    procedure g_search (Param : Individual); 

But you don't need to pass P, Q, and R, because you can get those from the parameter (Param.P, Param.Q, Param.R). 

Then you can't call g_search directly;  you have to instantiate it.

    function F(V : Individual) return Float is ... end F;
    function G(M : Individual) return Float is ... end G;

    function This_G_Search is new G_Search(F => F, G => G);

and now

    This_G_Search(V);

will call your search, and it will use the versions of F and G that you provided. 

Another possible way is to use access-to-procedure types.  But I think that for now, you need to go back and do more study about how generics work, and also discriminant records, and how parameter passing in Ada works in general.  Right now you seem to be guessing that if you name two variables or two functions with the same name, the language will magically connect everything together.  But it doesn't work like that.  That's why I think you need to back up a little and do some more reading about how Ada actually works.

                                -- Adam

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 18:19   ` Adam Beneschan
@ 2014-06-20 18:20     ` Adam Beneschan
  2014-06-21 20:56     ` Stephen Leake
  2014-06-22 12:27     ` Simon Clubley
  2 siblings, 0 replies; 18+ messages in thread
From: Adam Beneschan @ 2014-06-20 18:20 UTC (permalink / raw)


On Friday, June 20, 2014 11:19:57 AM UTC-7, Adam Beneschan wrote:

> Another possible way is to use access-to-procedure types.

I meant access-to-function.  

                             -- Adam


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 17:39 ` montgrimpulo
  2014-06-20 18:19   ` Adam Beneschan
@ 2014-06-20 20:39   ` Robert A Duff
  1 sibling, 0 replies; 18+ messages in thread
From: Robert A Duff @ 2014-06-20 20:39 UTC (permalink / raw)


montgrimpulo <aghte@hotlinemail.com> writes:

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

That won't work.  P, Q, and R are not initialized yet.  Assigning into
them later won't suddenly change the lengths of those arrays.
I think you want a discriminated record, as in:

    type Individual(P, Q, R : Natural) is record ...

> This is in principle what I want to set up and run, while I want to be
> flexible in defining F and G and other parameters, without having to
> modify the files search.ads and search.adb.

So you want (for example) P1 to call different versions of F?  If so,
then you can pass F into P1:

    procedure P1(F: not null access function (...) return ...);

Then the body of P1 can call F:

    procedure P1(F: not null access function (...) return ...) is
        XYZ : ... := F(...);
    begin
        ...

When you call P1, you create a function My_F, and pass My_F'Access to
P1:

    P1(F => My_F'Access);

- Bob

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 15:18 Function definitions montgrimpulo
                   ` (2 preceding siblings ...)
  2014-06-20 17:39 ` montgrimpulo
@ 2014-06-21 12:27 ` montgrimpulo
  2014-06-21 12:38   ` Simon Clubley
  2014-06-21 17:57   ` Jeffrey Carter
  2014-06-21 13:40 ` montgrimpulo
  4 siblings, 2 replies; 18+ messages in thread
From: montgrimpulo @ 2014-06-21 12:27 UTC (permalink / raw)


Here is another try to describe my problem.

I want to conduct a genetic optimisation-program. There is a function F (the objective function),
and a function G (the constraint function) which I can define only at runtime. The program handles
individuals within a population. The size of an individual as well as the size of the population are dynamic and only known at runtime. 

The proposed solution to define

generic
with function F (V : Individual) return Float;
with function G (V : Individual; M : Positive);
procedure Search (V : Individual)

seems to be an appropriate solution for that part.

The search program handles individuals from a population.

type x_array is array (positive range <>) of Float; 
type y_array is array (positive range <>) of Integer; 
type z_array is array (positive range <>) of Boolean; 

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

P,Q and R are only known at runtime.

Furthermore a population has a number of individuals (Popsize), which is also only known at runtime.

Due to some reading, I learned that dynamic arrays in Ada 

- can be declared in blocks, meaning no inheritance
- by limits passed as parameters in subprograms
- by use of linked lists
- by use of containers ?
- by use of discriminated records ?

looking at the proposed record from above:
Would it be OK to define

procedure Search (V : Individual) is
P : Natural := V.P;
Q : Natural := V.Q;
R : Natural := V.R;
Vi : Individual := V;

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

...
begin
-- fill Vi with distinct values and put it into an array?, container ?, List ?, whatever
-- work on all Vi's within that population
...
end Search;

What I still need is a definition for the population (a collection of Individuals), which size is determined at runtime.




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-21 12:27 ` montgrimpulo
@ 2014-06-21 12:38   ` Simon Clubley
  2014-06-21 17:57   ` Jeffrey Carter
  1 sibling, 0 replies; 18+ messages in thread
From: Simon Clubley @ 2014-06-21 12:38 UTC (permalink / raw)


On 2014-06-21, montgrimpulo <aghte@hotlinemail.com> wrote:
> Here is another try to describe my problem.
>
> I want to conduct a genetic optimisation-program. There is a function F (the objective function),
> and a function G (the constraint function) which I can define only at runtime. The program handles
> individuals within a population. The size of an individual as well as the size of the population are dynamic and only known at runtime. 
>

When you say F and G can only be defined at runtime, are you wanting to
dynamically generate Ada code at runtime and then execute it, or are you
just wanting to execute the same Ada code, but with different search
parameters and different sized arrays ?

I think the next stage is to try and find out what is so special about
F and G; you clearly need discriminated records, but I'm not yet 100%
convinced, for example, you need generics if this is just searching
for optimised values.

Also, can you talk about how these arrays are populated in the first
place and how that population process fits into the overall program
structure ?

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 15:18 Function definitions montgrimpulo
                   ` (3 preceding siblings ...)
  2014-06-21 12:27 ` montgrimpulo
@ 2014-06-21 13:40 ` montgrimpulo
  4 siblings, 0 replies; 18+ messages in thread
From: montgrimpulo @ 2014-06-21 13:40 UTC (permalink / raw)


I want to use my search program for a specific objective- and for a specific constraint-function with a certain size for an individual and a certain size of population. If I do not find a solution then I want to change some elements, eg. size of the population, size of an individual, or to try modified objective- or constraint-function.

After I have found a solution or not, I want to use the same search program with a new and different objective- and a new and different constraint function with a different size of an individual and a different population size.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-21 12:27 ` montgrimpulo
  2014-06-21 12:38   ` Simon Clubley
@ 2014-06-21 17:57   ` Jeffrey Carter
  1 sibling, 0 replies; 18+ messages in thread
From: Jeffrey Carter @ 2014-06-21 17:57 UTC (permalink / raw)


On 06/21/2014 05:27 AM, montgrimpulo wrote:
>
> I want to conduct a genetic optimisation-program.

You probably want to do something like this:

subtype Probability is Float range 0.0 .. 1.0;

generic -- Search
    type Gene is private;

    with function Random return Gene;
    -- For an initial random population

    with function Fitness (Individual : Gene) return Float;
    -- To evaluate Individual

    with function Mate (Left : Gene; Right : Gene) return Gene;
    -- Combines 2 individuals to produce an offspring

    with procedure Mutate (Individual : in out Gene);
    -- Randomly mutate Individual
procedure Search (Population_Size      : in     Positive;
                   Num_Generations      : in     Positive;
                   Mutation_Probability : in     Probability;
                   Best                 :    out Gene;
                   Fit                  :    out Float);

You can look at PragmARC.Genetic_Algorithm for an example

http://pragmada.x10hosting.com/pragmarc.htm

-- 
Jeff Carter
"If you don't get the President of the United States on that
phone, ... you're going to have to answer to the Coca-Cola
Company."
Dr. Strangelove
32


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 18:19   ` Adam Beneschan
  2014-06-20 18:20     ` Adam Beneschan
@ 2014-06-21 20:56     ` Stephen Leake
  2014-06-22 12:27     ` Simon Clubley
  2 siblings, 0 replies; 18+ messages in thread
From: Stephen Leake @ 2014-06-21 20:56 UTC (permalink / raw)


Adam Beneschan <adambeneschan@gmail.com> writes:

> First of all, if you want the bounds of Individual to be flexible,
> you'll need to make Individual a discriminant record:
>
>
>     type Individual (P, Q, R : Natural) is record 
>        X : x_array (0..P); 
>        Y : y_array (0..Q); 
>        Z : z_array (0..R); 
>     end record; 

or make Search generic:

generic
    P,Q,R : Natural; 
package Search is

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

    ...
end Search;

Then you have to instantiate Search in main_search.adb.

Which is better depends on many other things, in the full application.

-- 
-- Stephe

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 16:22 ` montgrimpulo
  2014-06-20 16:43   ` Adam Beneschan
  2014-06-20 16:43   ` Simon Clubley
@ 2014-06-22  6:59   ` Shark8
  2 siblings, 0 replies; 18+ messages in thread
From: Shark8 @ 2014-06-22  6:59 UTC (permalink / raw)


On 20-Jun-14 10:22, montgrimpulo wrote:
> My modified question:
>
> Hi,
> What would be an answer to the following question:
> There are three files : search.ads, search.adb, main_search.adb.
>
>   In search.ads two functions are defined:  function F and function G, as
>
> function F (V : Individual) return Long_Float; and
>
> function G(M : Natural; V : Individual) return Long_Float;
>
> Individual is defined as a Record containing several arrays
> with a size determined by variables, eg .
>
> type Individual is record
>   X : x_array (0 .. P);
>   Y : y_array (0 .. Q);
>   Z : z_array (0 .. R);
> end record;

That won't work as-is because arrays within records cannot be unconstrained.

You could make the package generic and use formal parameters though:

Generic
  P, Q, R : in Natural:= 0;
Package Search is
   type Individual is record
     X : x_array (0 .. P);
     Y : y_array (0 .. Q);
     Z : z_array (0 .. R);
   end record;

  function F (V : Individual) return Long_Float;
  function G (M : Natural; V : Individual) return Long_Float;

End Search;

--OR
You could use discriminants:
   type Individual(P,Q,R : Positive:= 1) is record
     X : x_array (0 .. P);
     Y : y_array (0 .. Q);
     Z : z_array (0 .. R);
   end record;



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function definitions
  2014-06-20 18:19   ` Adam Beneschan
  2014-06-20 18:20     ` Adam Beneschan
  2014-06-21 20:56     ` Stephen Leake
@ 2014-06-22 12:27     ` Simon Clubley
  2 siblings, 0 replies; 18+ messages in thread
From: Simon Clubley @ 2014-06-22 12:27 UTC (permalink / raw)


On 2014-06-20, Adam Beneschan <adambeneschan@gmail.com> wrote:
>
> Right now you seem to be guessing that if you name two variables or two
> functions with the same name, the language will magically connect everything
> together.  But it doesn't work like that.  That's why I think you need to back
> up a little and do some more reading about how Ada actually works.

Actually, in C (when using binutils) it does work like that by default
for some variable (but not function) definitions. It never occurred to
me that someone might apply the same reasoning to Ada code.

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2014-06-22 12:27 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-20 15:18 Function definitions montgrimpulo
2014-06-20 15:44 ` Adam Beneschan
2014-06-20 16:22 ` montgrimpulo
2014-06-20 16:43   ` Adam Beneschan
2014-06-20 16:52     ` Simon Clubley
2014-06-20 17:05       ` Adam Beneschan
2014-06-20 16:43   ` Simon Clubley
2014-06-22  6:59   ` Shark8
2014-06-20 17:39 ` montgrimpulo
2014-06-20 18:19   ` Adam Beneschan
2014-06-20 18:20     ` Adam Beneschan
2014-06-21 20:56     ` Stephen Leake
2014-06-22 12:27     ` Simon Clubley
2014-06-20 20:39   ` Robert A Duff
2014-06-21 12:27 ` montgrimpulo
2014-06-21 12:38   ` Simon Clubley
2014-06-21 17:57   ` Jeffrey Carter
2014-06-21 13:40 ` montgrimpulo

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