From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-3.2 required=3.0 tests=BAYES_00,NICE_REPLY_A, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R.Carter" Newsgroups: comp.lang.ada Subject: Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced? Date: Thu, 27 Jul 2023 10:53:35 +0200 Organization: A noiseless patient Spider Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 27 Jul 2023 08:53:35 -0000 (UTC) Injection-Info: dont-email.me; posting-host="1ecaee2de298624cd15f37b0e662cdcb"; logging-data="1941561"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18rR9clAi3pP/F0FJgZkiE32GbOi6mcq6s=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Cancel-Lock: sha1:rxaBiO44b4x+GC7SvFMiEMgzCHo= In-Reply-To: Content-Language: en-US Xref: news.eternal-september.org comp.lang.ada:65459 List-Id: On 2023-07-27 07:26, Kenneth Wolcott wrote: > > When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced? > > I'd like to slice out the first two digits from the output of the To_String function of Ada.Big_Numbers.Big_Integers. > > When trying to do the usual string slicing on the output I get a silent failure, it is just as if I typed the null statement. It would be helpful if you could show what you're doing and what results you get. This with Ada.Numerics.Discrete_Random; with Ada.Text_IO; procedure Func_Slice is subtype Digit is Character range '0' .. '9'; package Random is new Ada.Numerics.Discrete_Random (Result_Subtype => Digit); Gen : Random.Generator; function Image (N : in Natural) return String is (if N = 0 then "" else Random.Random (Gen) & Image (N - 1) ); -- Returns a string of N random Digits begin -- Func_Slice Random.Reset (Gen => Gen); Ada.Text_IO.Put_Line (Item => Image (10) (1 .. 2) ); end Func_Slice; works as expected $ gnatmake -m -j0 -gnat12 -gnatan -gnato2 -O2 -fstack-check func_slice.adb x86_64-linux-gnu-gcc-12 -c -gnat12 -gnatan -gnato2 -O2 -fstack-check func_slice.adb x86_64-linux-gnu-gnatbind-12 -x func_slice.ali x86_64-linux-gnu-gnatlink-12 func_slice.ali -O2 -fstack-check $ ./func_slice 10 $ ./func_slice 51 -- Jeff Carter "I would never want to belong to any club that would have someone like me for a member." Annie Hall 41