From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.184.8 with SMTP id i8mr30459269iof.85.1517656010804; Sat, 03 Feb 2018 03:06:50 -0800 (PST) X-Received: by 10.157.3.6 with SMTP id 6mr815118otv.3.1517656010611; Sat, 03 Feb 2018 03:06:50 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.am4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!g80no938056itg.0!news-out.google.com!k194ni3532itb.0!nntp.google.com!w142no934733ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 3 Feb 2018 03:06:50 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=87.116.179.50; posting-account=z-xFXQkAAABpEOAnT3LViyFXc8dmoW_p NNTP-Posting-Host: 87.116.179.50 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Array of records with default values not propagating to array From: Bojan Bozovic Injection-Date: Sat, 03 Feb 2018 11:06:50 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Received-Body-CRC: 982382563 X-Received-Bytes: 5009 Xref: reader02.eternal-september.org comp.lang.ada:50287 Date: 2018-02-03T03:06:50-08:00 List-Id: When I defined a record, and set a default value for some of its components= , these don't propagate when I make array of these records. Here is code th= at can be compiled, but I wonder do I need to explicitly assign value for '= others' in 'Initialize' procedure. This has nothing to do with Ada random n= umber generation, I might have as well used Ada.Numerics.Float_Random, or t= he reusable code that was posted in another thread, with the same result, s= o I will post in this separate thread. When I omit "others =3D>" in Initial= ize, I get compilation errors at these lines both on FSF compiler and AdaCo= re GPL compiler on Windows. Is this intended behavior or I am missing somet= hing? with Ada.Numerics.Discrete_Random; with Ada.Text_IO; with Ada.Text_IO.Unbounded_IO; with Ada.Strings; with Ada.Strings.Unbounded; procedure Tarot1 is Maximum_Deck_Length: constant integer :=3D 78; subtype Card_Position is Positive range 1..Maximum_Deck_Length; type Card_Suits is (Cups,Pentacles,Swords,Wands); type Trump_Values is new Natural range 0..21; type Card_Values is (Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Page,Knig= ht,Queen,King,Ace); type Card_Info (Trump: Boolean :=3D False) is record -- we will skip giving name and divinatory meaning to cards - its just ordi= nary assignment but for each card separately; -- PROBLEM: Assignment here does nothing, so I have to assign these values = in Initialize procedure below as well Name : Ada.Strings.Unbounded.Unbounded_String :=3D Ada.Strings.Unbounded.Nu= ll_Unbounded_String; Divinatory_Meaning: Ada.Strings.Unbounded.Unbounded_String :=3D Ada.Strings= .Unbounded.Null_Unbounded_String; case Trump is=20 when True =3D> Trump_Value:Trump_Values; when False =3D> Card_Value:Card_Values; Suit_Value:Card_Suits; end case; end record; type Deck is array (Card_Position) of Card_Info; package Card_Position_Random is new Ada.Numerics.Discrete_Random (Result_Su= btype =3D> Card_Position); procedure Initialize ( TDeck : in out Deck) is Index: Card_Position :=3D 1; begin -- first lay 22 trump cards in a deck for Index_1 in Trump_Values loop TDeck (Index) :=3D (Trump =3D> True, Trump_Value =3D> Index_1, others = =3D> Ada.Strings.Unbounded.Null_Unbounded_String); Index :=3D Index + 1; end loop; -- now lay 4 suits of 14 cards each; for Suit_Index in Card_Suits loop for Card_Index in Card_Values loop TDeck (Index) :=3D (Trump =3D> False, Card_Value =3D> Card_Index, Suit_V= alue =3D> Suit_Index, others =3D> Ada.Strings.Unbounded.Null_Unbounded_Stri= ng); exit when Index=3DMaximum_Deck_Length; -- preventing CONSTRAINT_ERROR; Index:=3DIndex+1; end loop; end loop; end Initialize; procedure Shuffle (TDeck : in out Deck) is Position_Gen : Card_Position_Random.Generator; Temporary_Data : Card_Info; Index_Random : Card_Position; begin Card_Position_Random.Reset (Gen =3D> Position_Gen); for Index in Card_Position loop Index_Random :=3D Card_Position_Random.Random (Gen =3D> Po= sition_Gen); Temporary_Data :=3D TDeck (Index); TDeck (Index) :=3D TDeck (Index_Random); TDeck (Index_Random) :=3D Temporary_Data; end loop; end Shuffle; Tarot_Deck : Deck; begin Initialize(Tarot_Deck); Shuffle(Tarot_Deck); for Index in Card_Position loop -- just print the deck as shuffled if Tarot_Deck(Index).Trump then Ada.Text_IO.Put_Line("Major Arcana/Trump: "&Trump_Values'Image(Tarot_Deck(= Index).Trump_Value)); else Ada.Text_IO.Put_Line("Minor Arcana: "&Card_Values'Image(Tarot_Deck(Index).= Card_Value)&" of "&Card_Suits'Image(Tarot_Deck(Index).Suit_Value)); end if; end loop; end Tarot1; Thanks for help.