Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

** MAXIMUM TERMINALS ACTIVE. TRY AGAIN LATER **


devel / comp.lang.ada / When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?

SubjectAuthor
* When using the Ada Big_Numbers.Big_Integers package, can theKenneth Wolcott
`* Re: When using the Ada Big_Numbers.Big_Integers package, can theJeffrey R.Carter
 `* Re: When using the Ada Big_Numbers.Big_Integers package, can theKenneth Wolcott
  +- Re: When using the Ada Big_Numbers.Big_Integers package, can theAdaMagica
  `* Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String functSimon Wright
   +- Re: When using the Ada Big_Numbers.Big_Integers package, can theKenneth Wolcott
   `* Re: When using the Ada Big_Numbers.Big_Integers package, can theAdaMagica
    `* Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String functKenneth Wolcott
     `* Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String functKenneth Wolcott
      `* Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String functRandy Brukardt
       `- Re: When using the Ada Big_Numbers.Big_Integers package, can theKenneth Wolcott

1
When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?

<b5e3d389-0bb0-41ac-8a47-6110a5b62d67n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9858&group=comp.lang.ada#9858

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:622a:14c9:b0:403:f3f9:850d with SMTP id u9-20020a05622a14c900b00403f3f9850dmr8631qtx.3.1690435584872;
Wed, 26 Jul 2023 22:26:24 -0700 (PDT)
X-Received: by 2002:a05:6808:1a03:b0:3a4:a629:6017 with SMTP id
bk3-20020a0568081a0300b003a4a6296017mr3758301oib.7.1690435584616; Wed, 26 Jul
2023 22:26:24 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Wed, 26 Jul 2023 22:26:24 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=98.59.238.112; posting-account=oHOvdQoAAACYgyEBjgPNvKFOGxg8pNns
NNTP-Posting-Host: 98.59.238.112
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b5e3d389-0bb0-41ac-8a47-6110a5b62d67n@googlegroups.com>
Subject: When using the Ada Big_Numbers.Big_Integers package, can the
To_String function output be sliced?
From: kennethwolcott@gmail.com (Kenneth Wolcott)
Injection-Date: Thu, 27 Jul 2023 05:26:24 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1704
 by: Kenneth Wolcott - Thu, 27 Jul 2023 05:26 UTC

Hi;

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.

Do I have to save the output to a variable via a declare block in order to get the slice to work?

This question is prompted by my attempt to solve the Rosetta Code task:

https://rosettacode.org/wiki/First_power_of_2_that_has_leading_decimal_digits_of_12

Thanks,
Ken Wolcott

Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?

<u9tbaf$1r81p$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9860&group=comp.lang.ada#9860

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (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
Lines: 47
Message-ID: <u9tbaf$1r81p$1@dont-email.me>
References: <b5e3d389-0bb0-41ac-8a47-6110a5b62d67n@googlegroups.com>
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: <b5e3d389-0bb0-41ac-8a47-6110a5b62d67n@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R.Carter - Thu, 27 Jul 2023 08:53 UTC

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

Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?

<be16b58d-d612-4d48-aae1-062818184a66n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9861&group=comp.lang.ada#9861

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:622a:1a13:b0:400:9f40:e4f4 with SMTP id f19-20020a05622a1a1300b004009f40e4f4mr3679qtb.6.1690498022522;
Thu, 27 Jul 2023 15:47:02 -0700 (PDT)
X-Received: by 2002:a05:6870:1aaf:b0:1bb:5605:df92 with SMTP id
ef47-20020a0568701aaf00b001bb5605df92mr1012601oab.10.1690498022140; Thu, 27
Jul 2023 15:47:02 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 27 Jul 2023 15:47:01 -0700 (PDT)
In-Reply-To: <u9tbaf$1r81p$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=98.59.238.112; posting-account=oHOvdQoAAACYgyEBjgPNvKFOGxg8pNns
NNTP-Posting-Host: 98.59.238.112
References: <b5e3d389-0bb0-41ac-8a47-6110a5b62d67n@googlegroups.com> <u9tbaf$1r81p$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <be16b58d-d612-4d48-aae1-062818184a66n@googlegroups.com>
Subject: Re: When using the Ada Big_Numbers.Big_Integers package, can the
To_String function output be sliced?
From: kennethwolcott@gmail.com (Kenneth Wolcott)
Injection-Date: Thu, 27 Jul 2023 22:47:02 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4867
 by: Kenneth Wolcott - Thu, 27 Jul 2023 22:47 UTC

On Thursday, July 27, 2023 at 1:53:38 AM UTC-7, Jeffrey R.Carter wrote:
> 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

Hi Jeff;

After going back and exhaustively reviewing the AdaCore Learning Introduction sections on Strings and Arrays, I determined that I was not slicing with the correct syntax for what I wanted to obtain, it seems that I was slicing built-in whitespace, not the digits I was looking for. So I am now extracting the two-digit slice using (2 .. 3) rather than (1 .. 2) and I am now obtaining the desired output. What I was trying to do was to obtain the slice from the string on the fly, not first saving the string to a variable..

This is what I have now (which works great):
---------------------------------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Numerics.Big_Numbers.Big_Integers; use Ada.Numerics.Big_Numbers.Big_Integers;

procedure Powers_Of_2_With_Leading_Digits_Of_12 is
Max : Positive := Integer'Value (Argument (1));
Powers_of_2 : Big_Positive := 1;
begin
for I in 1 .. Max loop
Powers_of_2 := Powers_of_2 * To_Big_Integer (2);
if I >= 4 then
declare
Powers_of_2_in_String_Format : String := To_String (Powers_of_2);
First_Pair_of_String_Digits : String := Powers_of_2_in_String_Format (2 .. 3);
begin
if First_Pair_of_String_Digits = "12" then
Put ("2^");
Put (I, 0);
Put_Line (To_String (Powers_of_2));
end if;
end; -- declare
end if;
end loop;
end Powers_Of_2_With_Leading_Digits_Of_12;
---------------------------------------------------------------------------

Now I can generalize this to more closely match the task requirements.

I think I tried to incorrectly create the slice from the To_String output directly without creating the variable in which to store the slice, which then requires the declare block.

Thanks,
Ken

Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?

<a34878b4-cd40-4c7d-b914-0f99761c7182n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9862&group=comp.lang.ada#9862

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:622a:1811:b0:406:804b:d67f with SMTP id t17-20020a05622a181100b00406804bd67fmr9361qtc.5.1690564744398;
Fri, 28 Jul 2023 10:19:04 -0700 (PDT)
X-Received: by 2002:a05:6870:98b2:b0:1bb:6993:1fb8 with SMTP id
eg50-20020a05687098b200b001bb69931fb8mr3890343oab.5.1690564744257; Fri, 28
Jul 2023 10:19:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 28 Jul 2023 10:19:03 -0700 (PDT)
In-Reply-To: <be16b58d-d612-4d48-aae1-062818184a66n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=3.73.42.116; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf
NNTP-Posting-Host: 3.73.42.116
References: <b5e3d389-0bb0-41ac-8a47-6110a5b62d67n@googlegroups.com>
<u9tbaf$1r81p$1@dont-email.me> <be16b58d-d612-4d48-aae1-062818184a66n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a34878b4-cd40-4c7d-b914-0f99761c7182n@googlegroups.com>
Subject: Re: When using the Ada Big_Numbers.Big_Integers package, can the
To_String function output be sliced?
From: christ-usch.grein@t-online.de (AdaMagica)
Injection-Date: Fri, 28 Jul 2023 17:19:04 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1337
 by: AdaMagica - Fri, 28 Jul 2023 17:19 UTC

To_String (Powers_of_2) (2 .. 3) should also work.

Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?

<lycz0baodn.fsf@pushface.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9863&group=comp.lang.ada#9863

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: simon@pushface.org (Simon Wright)
Newsgroups: comp.lang.ada
Subject: Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?
Date: Fri, 28 Jul 2023 19:21:08 +0100
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <lycz0baodn.fsf@pushface.org>
References: <b5e3d389-0bb0-41ac-8a47-6110a5b62d67n@googlegroups.com>
<u9tbaf$1r81p$1@dont-email.me>
<be16b58d-d612-4d48-aae1-062818184a66n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="5728df52d77c6c842acfbbf5e73a106f";
logging-data="2432113"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+wZ7D4slOUuYDQnu6kVEgiLsHXxSgqWzc="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (darwin)
Cancel-Lock: sha1:y5u8/jh+GLbg9Aq/eXG03MwWpLQ=
sha1:YI/vM5tlWz0D3CX1+RnzLN2xgrU=
 by: Simon Wright - Fri, 28 Jul 2023 18:21 UTC

This works for me:

for I in 1 .. Max loop
Powers_of_2 := Powers_of_2 * To_Big_Integer (2);
if I >= 4 then
if To_String (Powers_Of_2)(2 .. 3) = "12" then
Put ("2^");
Put (I, 0);
Put_Line (To_String (Powers_of_2));
end if;
end if;
end loop;

Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?

<e20dc905-4f1d-4224-b06a-24f4adcc8acbn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9864&group=comp.lang.ada#9864

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ad4:4b2d:0:b0:636:3fbd:84e with SMTP id s13-20020ad44b2d000000b006363fbd084emr13102qvw.5.1690601395599;
Fri, 28 Jul 2023 20:29:55 -0700 (PDT)
X-Received: by 2002:a05:6870:b7b3:b0:1bb:6e8a:d24e with SMTP id
ed51-20020a056870b7b300b001bb6e8ad24emr5341553oab.4.1690601395236; Fri, 28
Jul 2023 20:29:55 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 28 Jul 2023 20:29:54 -0700 (PDT)
In-Reply-To: <lycz0baodn.fsf@pushface.org>
Injection-Info: google-groups.googlegroups.com; posting-host=98.59.238.112; posting-account=oHOvdQoAAACYgyEBjgPNvKFOGxg8pNns
NNTP-Posting-Host: 98.59.238.112
References: <b5e3d389-0bb0-41ac-8a47-6110a5b62d67n@googlegroups.com>
<u9tbaf$1r81p$1@dont-email.me> <be16b58d-d612-4d48-aae1-062818184a66n@googlegroups.com>
<lycz0baodn.fsf@pushface.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e20dc905-4f1d-4224-b06a-24f4adcc8acbn@googlegroups.com>
Subject: Re: When using the Ada Big_Numbers.Big_Integers package, can the
To_String function output be sliced?
From: kennethwolcott@gmail.com (Kenneth Wolcott)
Injection-Date: Sat, 29 Jul 2023 03:29:55 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1968
 by: Kenneth Wolcott - Sat, 29 Jul 2023 03:29 UTC

On Friday, July 28, 2023 at 11:21:13 AM UTC-7, Simon Wright wrote:
> This works for me:
> for I in 1 .. Max loop
> Powers_of_2 := Powers_of_2 * To_Big_Integer (2);
> if I >= 4 then
> if To_String (Powers_Of_2)(2 .. 3) = "12" then
> Put ("2^");
> Put (I, 0);
> Put_Line (To_String (Powers_of_2));
> end if;
> end if;
> end loop;

Thanks to all for your responses...

I don't know exactly what I had tried that had failed, but I have learned more now, especially to be more observant.

I was able to simplify my code.

Greatly appreciate your patience with me.

Thanks,
Ken

Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?

<4364b66d-97a6-46c4-b11d-382aee086216n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9865&group=comp.lang.ada#9865

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:6214:1764:b0:635:49d7:544f with SMTP id et4-20020a056214176400b0063549d7544fmr15818qvb.4.1690628835591;
Sat, 29 Jul 2023 04:07:15 -0700 (PDT)
X-Received: by 2002:a9d:73c9:0:b0:6b8:92ea:23c4 with SMTP id
m9-20020a9d73c9000000b006b892ea23c4mr5814752otk.4.1690628835437; Sat, 29 Jul
2023 04:07:15 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Sat, 29 Jul 2023 04:07:15 -0700 (PDT)
In-Reply-To: <lycz0baodn.fsf@pushface.org>
Injection-Info: google-groups.googlegroups.com; posting-host=3.125.116.15; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf
NNTP-Posting-Host: 3.125.116.15
References: <b5e3d389-0bb0-41ac-8a47-6110a5b62d67n@googlegroups.com>
<u9tbaf$1r81p$1@dont-email.me> <be16b58d-d612-4d48-aae1-062818184a66n@googlegroups.com>
<lycz0baodn.fsf@pushface.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4364b66d-97a6-46c4-b11d-382aee086216n@googlegroups.com>
Subject: Re: When using the Ada Big_Numbers.Big_Integers package, can the
To_String function output be sliced?
From: christ-usch.grein@t-online.de (AdaMagica)
Injection-Date: Sat, 29 Jul 2023 11:07:15 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 5
 by: AdaMagica - Sat, 29 Jul 2023 11:07 UTC

> Powers_of_2 := Powers_of_2 * To_Big_Integer (2);

With the aspect Integer_Literal, also Powers_of_2 * 2 must work. The attributes Integer_Literal, Real_Literal, Put_Image make the new big numbers nearly work like numeric types (they are not). A difference: The range syntax for instance in loops A .. B is illegal.

Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?

<5c870602-e55e-4fe5-9f71-d5cf78d163fcn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9866&group=comp.lang.ada#9866

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a37:58c5:0:b0:76a:f46f:a04f with SMTP id m188-20020a3758c5000000b0076af46fa04fmr18064qkb.6.1690674547492; Sat, 29 Jul 2023 16:49:07 -0700 (PDT)
X-Received: by 2002:a05:6870:3a29:b0:1bb:b8f0:5878 with SMTP id du41-20020a0568703a2900b001bbb8f05878mr7254265oab.5.1690674547283; Sat, 29 Jul 2023 16:49:07 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!69.80.99.18.MISMATCH!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Sat, 29 Jul 2023 16:49:06 -0700 (PDT)
In-Reply-To: <4364b66d-97a6-46c4-b11d-382aee086216n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=98.59.238.112; posting-account=oHOvdQoAAACYgyEBjgPNvKFOGxg8pNns
NNTP-Posting-Host: 98.59.238.112
References: <b5e3d389-0bb0-41ac-8a47-6110a5b62d67n@googlegroups.com> <u9tbaf$1r81p$1@dont-email.me> <be16b58d-d612-4d48-aae1-062818184a66n@googlegroups.com> <lycz0baodn.fsf@pushface.org> <4364b66d-97a6-46c4-b11d-382aee086216n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5c870602-e55e-4fe5-9f71-d5cf78d163fcn@googlegroups.com>
Subject: Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?
From: kennethwolcott@gmail.com (Kenneth Wolcott)
Injection-Date: Sat, 29 Jul 2023 23:49:07 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 19
 by: Kenneth Wolcott - Sat, 29 Jul 2023 23:49 UTC

On Saturday, July 29, 2023 at 4:07:17 AM UTC-7, AdaMagica wrote:
> > Powers_of_2 := Powers_of_2 * To_Big_Integer (2);
> With the aspect Integer_Literal, also Powers_of_2 * 2 must work. The attributes Integer_Literal, Real_Literal, Put_Image make the new big numbers nearly work like numeric types (they are not). A difference: The range syntax for instance in loops A .. B is illegal.

I understand that the range syntax in loops implies that the loop variable is acting like an enumerated type which is not true for Big_Integers.

What confused me is that I thought I had to convert the numeric literal (I'll have to go back and look at the package spec again to get this firmly understood.

I have an another question about string slicing: I've tried (obviously incorrectly) to use a variable is one of the slice integers. Can this be done?

Thanks,
Ken

Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?

<2a5702b3-dbbc-4255-a4d4-e801f227fed3n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9867&group=comp.lang.ada#9867

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:622a:11d3:b0:40b:2fd7:55a8 with SMTP id n19-20020a05622a11d300b0040b2fd755a8mr10563qtk.8.1690674807552; Sat, 29 Jul 2023 16:53:27 -0700 (PDT)
X-Received: by 2002:a05:6870:1a81:b0:1ba:7bf5:67cd with SMTP id ef1-20020a0568701a8100b001ba7bf567cdmr7299856oab.11.1690674806965; Sat, 29 Jul 2023 16:53:26 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!69.80.99.15.MISMATCH!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Sat, 29 Jul 2023 16:53:26 -0700 (PDT)
In-Reply-To: <5c870602-e55e-4fe5-9f71-d5cf78d163fcn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=98.59.238.112; posting-account=oHOvdQoAAACYgyEBjgPNvKFOGxg8pNns
NNTP-Posting-Host: 98.59.238.112
References: <b5e3d389-0bb0-41ac-8a47-6110a5b62d67n@googlegroups.com> <u9tbaf$1r81p$1@dont-email.me> <be16b58d-d612-4d48-aae1-062818184a66n@googlegroups.com> <lycz0baodn.fsf@pushface.org> <4364b66d-97a6-46c4-b11d-382aee086216n@googlegroups.com> <5c870602-e55e-4fe5-9f71-d5cf78d163fcn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2a5702b3-dbbc-4255-a4d4-e801f227fed3n@googlegroups.com>
Subject: Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?
From: kennethwolcott@gmail.com (Kenneth Wolcott)
Injection-Date: Sat, 29 Jul 2023 23:53:27 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 62
 by: Kenneth Wolcott - Sat, 29 Jul 2023 23:53 UTC

On Saturday, July 29, 2023 at 4:49:08 PM UTC-7, Kenneth Wolcott wrote:
> On Saturday, July 29, 2023 at 4:07:17 AM UTC-7, AdaMagica wrote:
> > > Powers_of_2 := Powers_of_2 * To_Big_Integer (2);
> > With the aspect Integer_Literal, also Powers_of_2 * 2 must work. The attributes Integer_Literal, Real_Literal, Put_Image make the new big numbers nearly work like numeric types (they are not). A difference: The range syntax for instance in loops A .. B is illegal.
> I understand that the range syntax in loops implies that the loop variable is acting like an enumerated type which is not true for Big_Integers.
>
> What confused me is that I thought I had to convert the numeric literal (I'll have to go back and look at the package spec again to get this firmly understood.
>
> I have an another question about string slicing: I've tried (obviously incorrectly) to use a variable is one of the slice integers. Can this be done?
>
> Thanks,
> Ken

Apparently not :-(

gnatmake main.adb
gcc -c main.adb
main.adb:28:67: error: named parameters not permitted for attributes
9 with Ada.Text_IO; use Ada.Text_IO;
10 with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
11 with Ada.Float_Text_IO; use Ada.Float_Text_IO;
12 with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
13 with Ada.Command_Line; use Ada.Command_Line;
14
15 procedure Main is
16 Substr : String := Argument (1);
17 Nth : Positive := Integer'Value (Argument (2));
18 I, J : Natural;
19 Temp : Float;
20 begin
21 I := 0;
22 J := 0;
23 loop
24 I := I + 1;
25 exit when I >= 10;
26 Temp := 10.0 ** (log (2.0, 10.0) * Float (I));
27 if I >= 4 then
28 if (Float'Image (10.0 ** (log (2.0, 10.0) * Float (I)), Aft => 0, Exp => 0) (1 .. Substr'Length) = Substr then
29 J := J + 1;
30 if J = Nth then
31 Put (I, 0);
32 New_Line;
33 exit;
34 end if;
35 end if;
36 end if;
37 end loop;
38 end Main;

Thanks,
Ken

Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?

<ua4ppq$2smlt$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9868&group=comp.lang.ada#9868

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?
Date: Sat, 29 Jul 2023 23:43:53 -0500
Organization: A noiseless patient Spider
Lines: 74
Message-ID: <ua4ppq$2smlt$1@dont-email.me>
References: <b5e3d389-0bb0-41ac-8a47-6110a5b62d67n@googlegroups.com> <u9tbaf$1r81p$1@dont-email.me> <be16b58d-d612-4d48-aae1-062818184a66n@googlegroups.com> <lycz0baodn.fsf@pushface.org> <4364b66d-97a6-46c4-b11d-382aee086216n@googlegroups.com> <5c870602-e55e-4fe5-9f71-d5cf78d163fcn@googlegroups.com> <2a5702b3-dbbc-4255-a4d4-e801f227fed3n@googlegroups.com>
Injection-Date: Sun, 30 Jul 2023 04:43:39 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6e37c33987887416d5a164d6cba57085";
logging-data="3037885"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XTXZoP9zwgPcah5TzCxLeo098yMbCnR4="
Cancel-Lock: sha1:jEJXMYyeaVuyhw+TXiROyj+uxhI=
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-RFC2646: Format=Flowed; Original
X-MSMail-Priority: Normal
X-Priority: 3
 by: Randy Brukardt - Sun, 30 Jul 2023 04:43 UTC

'Image doesn't support any formatting, so no "Aft" or "Exp". The slicing
isn't the problem. :-)

You can use Text_IO to write to a string if you need formatting. 'Image is
for quick & dirty debugging, not fancy output. (Of course, if you're lucky
and it does what you need, then feel free to use it.)

Randy.

"Kenneth Wolcott" <kennethwolcott@gmail.com> wrote in message
news:2a5702b3-dbbc-4255-a4d4-e801f227fed3n@googlegroups.com...
On Saturday, July 29, 2023 at 4:49:08?PM UTC-7, Kenneth Wolcott wrote:
> On Saturday, July 29, 2023 at 4:07:17?AM UTC-7, AdaMagica wrote:
> > > Powers_of_2 := Powers_of_2 * To_Big_Integer (2);
> > With the aspect Integer_Literal, also Powers_of_2 * 2 must work. The
> > attributes Integer_Literal, Real_Literal, Put_Image make the new big
> > numbers nearly work like numeric types (they are not). A difference: The
> > range syntax for instance in loops A .. B is illegal.
> I understand that the range syntax in loops implies that the loop variable
> is acting like an enumerated type which is not true for Big_Integers.
>
> What confused me is that I thought I had to convert the numeric literal
> (I'll have to go back and look at the package spec again to get this
> firmly understood.
>
> I have an another question about string slicing: I've tried (obviously
> incorrectly) to use a variable is one of the slice integers. Can this be
> done?
>
> Thanks,
> Ken

Apparently not :-(

gnatmake main.adb
gcc -c main.adb
main.adb:28:67: error: named parameters not permitted for attributes
9 with Ada.Text_IO; use Ada.Text_IO;
10 with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
11 with Ada.Float_Text_IO; use Ada.Float_Text_IO;
12 with Ada.Numerics.Elementary_Functions; use
Ada.Numerics.Elementary_Functions;
13 with Ada.Command_Line; use Ada.Command_Line;
14
15 procedure Main is
16 Substr : String := Argument (1);
17 Nth : Positive := Integer'Value (Argument (2));
18 I, J : Natural;
19 Temp : Float;
20 begin
21 I := 0;
22 J := 0;
23 loop
24 I := I + 1;
25 exit when I >= 10;
26 Temp := 10.0 ** (log (2.0, 10.0) * Float (I));
27 if I >= 4 then
28 if (Float'Image (10.0 ** (log (2.0, 10.0) * Float (I)), Aft =>
0, Exp => 0) (1 .. Substr'Length) = Substr then
29 J := J + 1;
30 if J = Nth then
31 Put (I, 0);
32 New_Line;
33 exit;
34 end if;
35 end if;
36 end if;
37 end loop;
38 end Main;

Thanks,
Ken

Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?

<460be87a-b32a-4ef8-b295-79d67d95dee4n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9873&group=comp.lang.ada#9873

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ad4:4f33:0:b0:635:f3c8:860d with SMTP id fc19-20020ad44f33000000b00635f3c8860dmr37940qvb.11.1690832191720;
Mon, 31 Jul 2023 12:36:31 -0700 (PDT)
X-Received: by 2002:a05:6808:128a:b0:3a5:a79b:56b1 with SMTP id
a10-20020a056808128a00b003a5a79b56b1mr20164095oiw.9.1690832191539; Mon, 31
Jul 2023 12:36:31 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Mon, 31 Jul 2023 12:36:31 -0700 (PDT)
In-Reply-To: <ua4ppq$2smlt$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=98.59.238.112; posting-account=oHOvdQoAAACYgyEBjgPNvKFOGxg8pNns
NNTP-Posting-Host: 98.59.238.112
References: <b5e3d389-0bb0-41ac-8a47-6110a5b62d67n@googlegroups.com>
<u9tbaf$1r81p$1@dont-email.me> <be16b58d-d612-4d48-aae1-062818184a66n@googlegroups.com>
<lycz0baodn.fsf@pushface.org> <4364b66d-97a6-46c4-b11d-382aee086216n@googlegroups.com>
<5c870602-e55e-4fe5-9f71-d5cf78d163fcn@googlegroups.com> <2a5702b3-dbbc-4255-a4d4-e801f227fed3n@googlegroups.com>
<ua4ppq$2smlt$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <460be87a-b32a-4ef8-b295-79d67d95dee4n@googlegroups.com>
Subject: Re: When using the Ada Big_Numbers.Big_Integers package, can the
To_String function output be sliced?
From: kennethwolcott@gmail.com (Kenneth Wolcott)
Injection-Date: Mon, 31 Jul 2023 19:36:31 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Kenneth Wolcott - Mon, 31 Jul 2023 19:36 UTC

On Saturday, July 29, 2023 at 9:43:42 PM UTC-7, Randy Brukardt wrote:
> 'Image doesn't support any formatting, so no "Aft" or "Exp". The slicing
> isn't the problem. :-)
>
> You can use Text_IO to write to a string if you need formatting. 'Image is
> for quick & dirty debugging, not fancy output. (Of course, if you're lucky
> and it does what you need, then feel free to use it.)

Hi Randy;

Thank you for your input.

I think I was (maybe I still am) suffering from the "sprintf" "disease" from Perl (and C).

Thanks,
Ken

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor