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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3f1374bc66d2dc03 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.scarlet.biz!news.scarlet.biz.POSTED!not-for-mail NNTP-Posting-Date: Wed, 15 Feb 2006 15:55:31 -0600 From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: creating an array References: <1139897171.996297.230070@z14g2000cwz.googlegroups.com> <1139951664.264622.240870@z14g2000cwz.googlegroups.com> <1139955455.397334.310790@g43g2000cwa.googlegroups.com> <878xsd8sqq.fsf@ludovic-brenta.org> <1139957691.430522.159580@o13g2000cwo.googlegroups.com> <874q318rkd.fsf@ludovic-brenta.org> <1139960269.338824.166090@g14g2000cwa.googlegroups.com> Date: Wed, 15 Feb 2006 22:53:46 +0100 Message-ID: <87u0b070gl.fsf@ludovic-brenta.org> User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:8v9ZxVSIyOMP8mmGOwQel4hrG4g= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 83.134.239.36 X-Trace: sv3-zi4wLqiQPAvn1UP8ev/tpL0uHqjIDXkFtIlrgHT1R84mCFPOxTn+M3qHV1H9YudjcAziBMXPSAH3fx9!ozTUTcTAU8HnigNR3vdP7Y/7WC4ulzlLW10H9gp1MaIisN53R/963pL1pZfmrJPvLf0rkHo02A== X-Complaints-To: abuse@scarlet.be X-DMCA-Complaints-To: abuse@scarlet.biz X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:2911 Date: 2006-02-15T22:53:46+01:00 List-Id: "isaac2004" writes: >>But I still think my solution is much, much better :) > sorry havent learned that far yet, but i cant seem to get your code > to work by itself, it throws a error about a loop where the first if > statement is. oh well it wasnt tested but i would like ot see a > running program of that if possible. OK, it took me another minute or two. Here is the corrected version, followed by the diff so you can see what I changed. (in retrospect, "if X not in 1 .. 10" reads better than "if not X in 1 .. 10", don't you think? -- Ludovic Brenta. -- Caveat student: not compiled or tested; just wrote this in 10 minutes. -- Caveat student: your teacher probably reads c.l.a, too :) with Ada.Integer_Text_IO; with Ada.Text_IO; procedure Sort_And_Display is subtype Digit_Type is Character range '0' .. '9'; type Occurrences_Type is array (Digit_Type) of Natural; Expected_Number_Of_Digits : Positive; User_Input : String (1 .. 10); Last : Natural; Occurrences : Occurrences_Type := (others => 0); Bad_Input : exception; begin Ada.Text_IO.Put ("How many digits (1 .. 10)? "); Ada.Integer_Text_IO.Get (Expected_Number_Of_Digits); Ada.Text_IO.Skip_Line; if Expected_Number_Of_Digits not in 1 .. 10 then raise Bad_Input; end if; Ada.Text_IO.Put ("Now type your number consisting of " & Integer'Image (Expected_Number_Of_Digits) & " digits: "); Ada.Text_IO.Get_Line (User_Input, Last); if Last > Expected_Number_Of_Digits then raise Bad_Input; end if; -- Parse the character string for J in 1 .. Last loop if User_Input (J) not in Digit_Type then raise Bad_Input; end if; Occurrences (User_Input (J)) := Occurrences (User_Input (J)) + 1; end loop; -- Now, Occurrences is naturally sorted; just walk over it. for K in Occurrences'Range loop for L in 1 .. Occurrences (K) loop Ada.Text_IO.Put (K); end loop; end loop; end Sort_And_Display; --- /tmp/ediff10085Ca 2006-02-15 22:51:09.000000000 +0100 +++ /tmp/sort_and_display.adb 2006-02-15 22:51:09.000000000 +0100 @@ -1,6 +1,7 @@ -- Caveat student: not compiled or tested; just wrote this in 10 minutes. -- Caveat student: your teacher probably reads c.l.a, too :) -with Ada.Text_IO.Integer_IO; +with Ada.Integer_Text_IO; +with Ada.Text_IO; procedure Sort_And_Display is subtype Digit_Type is Character range '0' .. '9'; type Occurrences_Type is array (Digit_Type) of Natural; @@ -11,13 +12,13 @@ Bad_Input : exception; begin Ada.Text_IO.Put ("How many digits (1 .. 10)? "); - Ada.Text_IO.Integer_IO.Get (Expected_Number_Of_Digits); + Ada.Integer_Text_IO.Get (Expected_Number_Of_Digits); Ada.Text_IO.Skip_Line; - if not Expected_Number_Of_Digits in 1 .. 10 then + if Expected_Number_Of_Digits not in 1 .. 10 then raise Bad_Input; end if; Ada.Text_IO.Put ("Now type your number consisting of " & - Integer'Image (Expected_Number_Of_Digit) & + Integer'Image (Expected_Number_Of_Digits) & " digits: "); Ada.Text_IO.Get_Line (User_Input, Last); if Last > Expected_Number_Of_Digits then @@ -26,11 +27,11 @@ -- Parse the character string for J in 1 .. Last loop - if not User_Input (J) in Digit_Type then + if User_Input (J) not in Digit_Type then raise Bad_Input; end if; Occurrences (User_Input (J)) := Occurrences (User_Input (J)) + 1; - end if; + end loop; -- Now, Occurrences is naturally sorted; just walk over it. for K in Occurrences'Range loop