* Variant record with multiple discriminants?
@ 2017-10-28 17:05 Victor Porton
2017-10-28 18:47 ` Niklas Holsti
2017-10-28 18:48 ` Dmitry A. Kazakov
0 siblings, 2 replies; 3+ messages in thread
From: Victor Porton @ 2017-10-28 17:05 UTC (permalink / raw)
Ada does not support variant records whose fields presence depends on
multiple discriminants, does it?
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Variant record with multiple discriminants?
2017-10-28 17:05 Variant record with multiple discriminants? Victor Porton
@ 2017-10-28 18:47 ` Niklas Holsti
2017-10-28 18:48 ` Dmitry A. Kazakov
1 sibling, 0 replies; 3+ messages in thread
From: Niklas Holsti @ 2017-10-28 18:47 UTC (permalink / raw)
On 17-10-28 20:05 , Victor Porton wrote:
> Ada does not support variant records whose fields presence depends on
> multiple discriminants, does it?
Yes it does, in two ways:
- a component in a variant (RM 3.8.1) can itself be of a discriminated
record type, and can take the actual value of its discriminant from some
discriminant of the containing record
- the component_list in a variant can contain nested variant_parts, that
is, the "case .. when .. when .. end case" structure can be nested.
Example:
type Int_Or_Char_T (Is_Int : Boolean)
is record
case Is_Int is
when True => I : Integer;
when False => C : Character;
end case;
end record;
type Float_Or_Int_Or_Char_1_T (Is_Float : Boolean; Is_Int : Boolean)
is record
case Is_Float is
when True => F : Float;
when False => IC : Int_Or_Char_T (Is_Int);
end case;
end record;
type Float_Or_Int_Or_Char_2_T (Is_Float : Boolean; Is_Int : Boolean)
is record
case Is_Float is
when True => F : Float;
when False =>
case Is_Int is
when True => I : Integer;
when False => C : Character;
end case;
end case;
end record;
The main limitation is that the values used in the "case" constructs, or
supplied as actual discriminant values for sub-records, must be
discriminants of the parent record, and cannot be computed expressions.
For example, it would be illegal to declare the "IC" component in this
way, using a Boolean expression as the discriminant value:
when False => IC : Int_Or_Char_T (not Is_Int);
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Variant record with multiple discriminants?
2017-10-28 17:05 Variant record with multiple discriminants? Victor Porton
2017-10-28 18:47 ` Niklas Holsti
@ 2017-10-28 18:48 ` Dmitry A. Kazakov
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry A. Kazakov @ 2017-10-28 18:48 UTC (permalink / raw)
On 2017-10-28 19:05, Victor Porton wrote:
> Ada does not support variant records whose fields presence depends on
> multiple discriminants, does it?
type T (A : Boolean; B : Boolean) is record
case A is
when True =>
case B is
when True =>
X : Integer;
when False =>
Y : Float;
end case;
when False =>
Z : String (1..20);
end case;
end record;
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-10-28 18:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-28 17:05 Variant record with multiple discriminants? Victor Porton
2017-10-28 18:47 ` Niklas Holsti
2017-10-28 18:48 ` Dmitry A. Kazakov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox