From: "Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not>
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 [thread overview]
Message-ID: <u9tbaf$1r81p$1@dont-email.me> (raw)
In-Reply-To: <b5e3d389-0bb0-41ac-8a47-6110a5b62d67n@googlegroups.com>
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
next prev parent reply other threads:[~2023-07-27 8:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-27 5:26 When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced? Kenneth Wolcott
2023-07-27 8:53 ` Jeffrey R.Carter [this message]
2023-07-27 22:47 ` Kenneth Wolcott
2023-07-28 17:19 ` AdaMagica
2023-07-28 18:21 ` Simon Wright
2023-07-29 3:29 ` Kenneth Wolcott
2023-07-29 11:07 ` AdaMagica
2023-07-29 23:49 ` Kenneth Wolcott
2023-07-29 23:53 ` Kenneth Wolcott
2023-07-30 4:43 ` Randy Brukardt
2023-07-31 19:36 ` Kenneth Wolcott
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox