From: Pierre Van Aswegen <pvana@iossvr.gm.hac.com>
Subject: New language feature to check record coverage?
Date: 1997/02/25
Date: 1997-02-25T00:00:00+00:00 [thread overview]
Message-ID: <33139C04.57DB@iossvr.gm.hac.com> (raw)
I would like those who collect ideas for the evolution of the language
to tell me what they think of the following idea. It is unprecedented
in any language I know, but suggested slightly by combining the idea
that the compiler checks that you have an entry for each value in a case
statement and the use of record aggregate assigment to ensure you have a
value for each member of the aggregate.
The need I perceive stems from writing a validation function to certify
that the values in a record are consistent. If I change the definition
of the record (or miss a member in the original function), the compiler
is not going to remind me to update the validation function. (As it
would remind me to fix case statements if I changed an enumeration or to
fix an aggregate assignment of said changed record.) I have encountered
other situations where I've wished to have some guarantee that I was
addressing every part of a record.
What one needs is a kind of iterator for which the user must supply an
operation for each member of a record. (Some members can share an
operation.) A reasonably understandable syntax can be derived from
either case or aggregation.
type Some_Record is
record
A_Member : MemberA;
B_Member : MemberB;
...
end record;
function Is_Consistent return Boolean is
Answer : Boolean := True;
begin
case Members'Some_Record --*
when A_Member => ...; --*
when B_Member => ...; --*
...
end case;
return Answer;
end Is_Consistent;
function Is_Consistent return Boolean is
Answer : Boolean := True;
begin
Members'Some_Record --*
(A_Member => ..., --*
B_Member => ..., --*
...)
return Answer;
end Is_Consistent;
*"fantasy Ada"
next reply other threads:[~1997-02-25 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-02-25 0:00 Pierre Van Aswegen [this message]
1997-02-26 0:00 ` New language feature to check record coverage? Geert Bosch
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox