comp.lang.ada
 help / color / mirror / Atom feed
* inherited discriminant not allowed here
@ 2017-03-08 20:34 hreba
  2017-03-09  2:49 ` Randy Brukardt
  0 siblings, 1 reply; 3+ messages in thread
From: hreba @ 2017-03-08 20:34 UTC (permalink / raw)


The idea is the following: I want a "numeric function" which stores the 
y values in a hidden array:

private
    type Tuple is array (Positive range <>) of Real;

    type FuncD (maxlen: Positive) is abstract tagged limited record
       xmin, xmax, ymin, ymax:	Real;
       y:			Tuple (1..maxlen);
       n:			Natural:= 0;	-- # of used points
    end record;

The first derivation has equidistant x values:

    type FuncED is new FuncD with record
       dx:		Real;
    end record;

The second one is not equidistant and stores the x-values too in an array:

    type FuncNE is new FuncD with record
       x:		Tuple(1..maxlen);
    end record;

But the compiler doesn't let me do that. He says:

    inherited discriminant not allowed here (RM 3.8 (12), 3.8.1 (6))

Is there any solution, workaround, alternative? What would you do?

-- 
Frank Hrebabetzky		+49 / 6355 / 989 5070


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

* Re: inherited discriminant not allowed here
  2017-03-08 20:34 inherited discriminant not allowed here hreba
@ 2017-03-09  2:49 ` Randy Brukardt
  2017-03-09 10:10   ` hreba
  0 siblings, 1 reply; 3+ messages in thread
From: Randy Brukardt @ 2017-03-09  2:49 UTC (permalink / raw)


"hreba" <f_hreba@yahoo.com.br> wrote in message 
news:eib860Fe05dU1@mid.individual.net...
> The idea is the following: I want a "numeric function" which stores the y 
> values in a hidden array:
>
> private
>    type Tuple is array (Positive range <>) of Real;
>
>    type FuncD (maxlen: Positive) is abstract tagged limited record
>       xmin, xmax, ymin, ymax: Real;
>       y: Tuple (1..maxlen);
>       n: Natural:= 0; -- # of used points
>    end record;
>
> The first derivation has equidistant x values:
>
>    type FuncED is new FuncD with record
>       dx: Real;
>    end record;
>
> The second one is not equidistant and stores the x-values too in an array:
>
>    type FuncNE is new FuncD with record
>       x: Tuple(1..maxlen);
>    end record;
>
> But the compiler doesn't let me do that. He says:
>
>    inherited discriminant not allowed here (RM 3.8 (12), 3.8.1 (6))
>
> Is there any solution, workaround, alternative? What would you do?

You have to declare the discriminant locally. But you can do that:

    type FuncNE  (NE_maxlen: Positive) is new FuncD (NE_maxlen) with record
       x: Tuple(1..NE_maxlen);
    end record;

Here the new discriminant is used to constrain the old discriminant; the new 
discriminant is essentially a renaming of the old one.

I changed the name of the discriminant because this feature is rarely used 
and tends to be buggy (there's not many ACATS tests, for instance). So I'd 
minimize the likelyhood of trouble by making sure everything has distinct 
names. (But that's just me, feel free to live dangerously if you like. ;-)

                                      Randy.

P.S. I didn't actually try this. 



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

* Re: inherited discriminant not allowed here
  2017-03-09  2:49 ` Randy Brukardt
@ 2017-03-09 10:10   ` hreba
  0 siblings, 0 replies; 3+ messages in thread
From: hreba @ 2017-03-09 10:10 UTC (permalink / raw)


On 03/09/2017 03:49 AM, Randy Brukardt wrote:
> "hreba" <f_hreba@yahoo.com.br> wrote in message
> news:eib860Fe05dU1@mid.individual.net...
>> The idea is the following: I want a "numeric function" which stores the y
>> values in a hidden array:
>>
>> private
>>    type Tuple is array (Positive range <>) of Real;
>>
>>    type FuncD (maxlen: Positive) is abstract tagged limited record
>>       xmin, xmax, ymin, ymax: Real;
>>       y: Tuple (1..maxlen);
>>       n: Natural:= 0; -- # of used points
>>    end record;
>>
>> The first derivation has equidistant x values:
>>
>>    type FuncED is new FuncD with record
>>       dx: Real;
>>    end record;
>>
>> The second one is not equidistant and stores the x-values too in an array:
>>
>>    type FuncNE is new FuncD with record
>>       x: Tuple(1..maxlen);
>>    end record;
>>
>> But the compiler doesn't let me do that. He says:
>>
>>    inherited discriminant not allowed here (RM 3.8 (12), 3.8.1 (6))
>>
>> Is there any solution, workaround, alternative? What would you do?
>
> You have to declare the discriminant locally. But you can do that:
>
>     type FuncNE  (NE_maxlen: Positive) is new FuncD (NE_maxlen) with record
>        x: Tuple(1..NE_maxlen);
>     end record;
>
> Here the new discriminant is used to constrain the old discriminant; the new
> discriminant is essentially a renaming of the old one.
>
> I changed the name of the discriminant because this feature is rarely used
> and tends to be buggy (there's not many ACATS tests, for instance). So I'd
> minimize the likelyhood of trouble by making sure everything has distinct
> names. (But that's just me, feel free to live dangerously if you like. ;-)
>
>                                       Randy.
>
> P.S. I didn't actually try this.
>
>

I tried it, with the result:

    only static constraints allowed for parent discriminants in the
    partial view.

Somehow, the package should be parametrized. This led me to the 
following idea: it is generic anyway (type Real), so I added another 
parameter for the index range:

generic
    type Index is range <>;	-- maximum range
    type Real is digits <>;	-- x and y value type
package NumFunc is
...
    type Tuple is array (Index) of Real;

Now my x and y arrays are of type Tuple, without any more need for 
parametrized records. It seems to work.

Thanks for your hint, it got me on the right trace.
-- 
Frank Hrebabetzky		+49 / 6355 / 989 5070


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

end of thread, other threads:[~2017-03-09 10:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-08 20:34 inherited discriminant not allowed here hreba
2017-03-09  2:49 ` Randy Brukardt
2017-03-09 10:10   ` hreba

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