with ada.text_io; use ada.text_io; with ada.integer_text_io; use ada.integer_text_io; procedure basic_recs is -- Declare a record type with two FIELDS -- Its fields do not have default values type P1 is record x: Natural; y: Natural; end record; -- For this type, the fields do have default values type P2 is record x: Natural := 1; y: Natural := 2; end record; -- Declaration allocates record with specified name a1: P1; -- Fields have unknown values a2: P2; -- Fields have default values -- Explicit initialization. -- Overrides any default values. b1: P1 := (3, 4); -- (3, 4) is an aggregate value b2: P2 := (y => 6, others => 5); -- Keywords. begin put(b1.x); -- 3 put(b2.y); -- 6 put(a1.x); -- Unknown value printed a1.x := 7; -- Assign one field put(a1.x); -- 7 -- Assign with aggregate value a1 := (8, 9); a2 := (x => 8, y => 9); -- Keyword aggregate put(a1.x); -- 8 b1 := (others => 10); -- Others works too put(b1.x); -- 10 -- Element by element assignment and comparison if a1 = b1 then put("EQ"); else put("NE"); end if; a1 := b1; if a1 = b1 then put("EQ"); else put("NE"); end if; -- Type names must match for := and =. -- a1 := a2; -- Compile error -- if a1 = a2 then put("EQ"); else put("NE"); end if; -- Value semantics. Compare with Java. a1.x := 99; if a1 = b1 then put("EQ"); else put("NE"); end if; put(b1.x); end basic_recs;