comp.lang.ada
 help / color / mirror / Atom feed
* New language feature to check record coverage?
@ 1997-02-25  0:00 Pierre Van Aswegen
  1997-02-26  0:00 ` Geert Bosch
  0 siblings, 1 reply; 2+ messages in thread
From: Pierre Van Aswegen @ 1997-02-25  0:00 UTC (permalink / 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"




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

end of thread, other threads:[~1997-02-26  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-02-25  0:00 New language feature to check record coverage? Pierre Van Aswegen
1997-02-26  0:00 ` Geert Bosch

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