Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

No, that'd be silly. -- Larry Wall in <199710221710.KAA24242@wall.org>


devel / comp.lang.ada / Re: Empty String confusion; Positive and Natural

SubjectAuthor
* Empty String confusion; Positive and NaturalKevin Chadwick
+- Re: Empty String confusion; Positive and NaturalJeffrey R.Carter
+* Re: Empty String confusion; Positive and NaturalNiklas Holsti
|`* Re: Empty String confusion; Positive and NaturalKevin Chadwick
| +- Re: Empty String confusion; Positive and NaturalSimon Wright
| +- Re: Empty String confusion; Positive and NaturalNiklas Holsti
| `* Re: Empty String confusion; Positive and NaturalJeffrey R.Carter
|  `* Re: Empty String confusion; Positive and NaturalKevin Chadwick
|   `* Re: Empty String confusion; Positive and NaturalJ-P. Rosen
|    `- Re: Empty String confusion; Positive and NaturalKevin Chadwick
`* Re: Empty String confusion; Positive and Naturalldries46
 `* Re: Empty String confusion; Positive and NaturalSimon Wright
  `- Re: Empty String confusion; Positive and Naturalldries46

1
Empty String confusion; Positive and Natural

<053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ad4:5de3:: with SMTP id jn3mr44788786qvb.22.1638207288448;
Mon, 29 Nov 2021 09:34:48 -0800 (PST)
X-Received: by 2002:a25:b8c7:: with SMTP id g7mr36111024ybm.115.1638207288272;
Mon, 29 Nov 2021 09:34:48 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.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: Mon, 29 Nov 2021 09:34:47 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=92.40.203.37; posting-account=5K6RMgoAAADQeoHIOMi2dg5aYc0IVxGi
NNTP-Posting-Host: 92.40.203.37
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
Subject: Empty String confusion; Positive and Natural
From: kevc3...@gmail.com (Kevin Chadwick)
Injection-Date: Mon, 29 Nov 2021 17:34:48 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 8
 by: Kevin Chadwick - Mon, 29 Nov 2021 17:34 UTC

I suspect that I am doing something outside of Ada norms.

Are empty strings avoided in Ada?

I have a function to create a record containing strings amongst other things like a subtyped integer, simply to group the outputs neatly of another function.

If something goes wrong and I run the create function with "" then the strings length is zero. Why is a string type Positive and not Natural, because empty strings are in fact useless?

I guess I shall consider re-engineering my functions, rather than add checks, but all thoughts are welcome.

Re: Empty String confusion; Positive and Natural

<so34p1$g6r$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: spam.jrc...@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: Empty String confusion; Positive and Natural
Date: Mon, 29 Nov 2021 19:05:21 +0100
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <so34p1$g6r$1@dont-email.me>
References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 29 Nov 2021 18:05:21 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="670b459fad2f9af77ded0cc30bb39b80";
logging-data="16603"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8wFIVrYBfPeBDU+mNAIWPrGCIONTMZr8="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.3.1
Cancel-Lock: sha1:KgYehkYVqAK1mEemQfquVcZAbcg=
In-Reply-To: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R.Carter - Mon, 29 Nov 2021 18:05 UTC

On 2021-11-29 18:34, Kevin Chadwick wrote:
>
> If something goes wrong and I run the create function with "" then the strings length is zero. Why is a string type Positive and not Natural, because empty strings are in fact useless?

I don't understand what you're asking. 'Length returns
universal_integer; it is independent of the index subtype. The index
subtype can even be non-numeric.

--
Jeff Carter
Programming by extension, emphasizing, as it does,
ease of writing over ease of reading, should be
avoided whenever possible by S/W engineers, and
used with the same reluctance and care that they
give to gotos and access types.
175

Re: Empty String confusion; Positive and Natural

<j0kndlFnvleU1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.h...@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: Empty String confusion; Positive and Natural
Date: Mon, 29 Nov 2021 21:19:16 +0200
Organization: Tidorum Ltd
Lines: 42
Message-ID: <j0kndlFnvleU1@mid.individual.net>
References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net qKzs4ahAdx5Fs7XUnaIYow7o+/eteU0wkUrfC3I5oFa3zLEDUq
Cancel-Lock: sha1:gzT1oXWavUtYAQH3vfnuvTxl4bc=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0)
Gecko/20100101 Thunderbird/78.14.0
In-Reply-To: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
Content-Language: en-US
 by: Niklas Holsti - Mon, 29 Nov 2021 19:19 UTC

On 2021-11-29 19:34, Kevin Chadwick wrote:
> I suspect that I am doing something outside of Ada norms.
>
> Are empty strings avoided in Ada?

No, empty strings (and empty arrays in general) are quite usable.

> I have a function to create a record containing strings amongst other
> things like a subtyped integer, simply to group the outputs neatly of
> another function.

It would clarify your question if you would show the declaration of that
record type. Does it use the String type, or the Unbounded_String type?

> If something goes wrong and I run the create function with "" then
> the strings length is zero.

Is there something wrong with that? An empty string should have length
zero, it seems to me.

> Why is a string type Positive and not Natural, because empty strings
> are in fact useless?

An object S : String is an empty string if and only if S'Length = 0.
(And, as Jeff said, S'Length is not a Positive, but a universal integer,
so it can be zero even if Strings are indexed with Positive numbers.)

Also, an object S : String is an empty string if and only if S'Last <
S'First. Note that S'Last can be much less than S'First, so in this case
you cannot compute the length of the string from S'Last - S'First + 1.
Or if you do, you can get a negative result, and understand that as zero
length.

The case where S'Last is much less than S'First usually comes about when
one takes an empty slice of an existing string, for example X(5 .. 2),
where X is for example String (1 .. 10).

Re: Empty String confusion; Positive and Natural

<bea93bf3-f282-4e9b-8806-2b956d58fe51n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:7d47:: with SMTP id h7mr39067064qtb.486.1638226226397;
Mon, 29 Nov 2021 14:50:26 -0800 (PST)
X-Received: by 2002:a5b:950:: with SMTP id x16mr9366086ybq.675.1638226226229;
Mon, 29 Nov 2021 14:50:26 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.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: Mon, 29 Nov 2021 14:50:25 -0800 (PST)
In-Reply-To: <j0kndlFnvleU1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23c0:f583:ec01:68ac:7834:980a:da59;
posting-account=5K6RMgoAAADQeoHIOMi2dg5aYc0IVxGi
NNTP-Posting-Host: 2a00:23c0:f583:ec01:68ac:7834:980a:da59
References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com> <j0kndlFnvleU1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bea93bf3-f282-4e9b-8806-2b956d58fe51n@googlegroups.com>
Subject: Re: Empty String confusion; Positive and Natural
From: kevc3...@gmail.com (Kevin Chadwick)
Injection-Date: Mon, 29 Nov 2021 22:50:26 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 7
 by: Kevin Chadwick - Mon, 29 Nov 2021 22:50 UTC

> It would clarify your question if you would show the declaration of that
> record type. Does it use the String type, or the Unbounded_String type?

Hopefully I will have a doh moment when I get into the office in the morning and post code. I am getting a range check exception when I assign "" to a standard.String in a record by returning the record from a function. Surely, I must have caused it somehow.

Re: Empty String confusion; Positive and Natural

<nnd$23404336$0a486277@9b8ca000aec60c20>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Date: Tue, 30 Nov 2021 08:40:41 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Subject: Re: Empty String confusion; Positive and Natural
Content-Language: en-GB
Newsgroups: comp.lang.ada
References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
From: bertus.d...@planet.nl (ldries46)
In-Reply-To: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <nnd$23404336$0a486277@9b8ca000aec60c20>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 21
Injection-Date: Tue, 30 Nov 2021 08:40:44 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2169
 by: ldries46 - Tue, 30 Nov 2021 07:40 UTC

Op 29-11-2021 om 18:34 schreef Kevin Chadwick:
> I suspect that I am doing something outside of Ada norms.
>
> Are empty strings avoided in Ada?
>
> I have a function to create a record containing strings amongst other things like a subtyped integer, simply to group the outputs neatly of another function.
>
> If something goes wrong and I run the create function with "" then the strings length is zero. Why is a string type Positive and not Natural, because empty strings are in fact useless?
>
> I guess I shall consider re-engineering my functions, rather than add checks, but all thoughts are welcome.
From your description, I suspect that you are using different
declarations for the strings you use for instance while " " in fact is a
string(1.1) you try to put this in a string(1 .. 5).
To avoid this kind of problems I generally use the package
Ada.Strings.Unbounded where have possibilities to operate strings
without caring for the length. Changing between strings and unbounded
strings is possible with functions in the package.
I would then advice you to create an variable at a position where it is
reachable from all packages where you use it:
Empty_String : Unbounded_String := To_Unbounded_String("");

Re: Empty String confusion; Positive and Natural

<lytufuvyt3.fsf@pushface.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!8nKyDL3nVTTIdBB8axZhRA.user.46.165.242.75.POSTED!not-for-mail
From: sim...@pushface.org (Simon Wright)
Newsgroups: comp.lang.ada
Subject: Re: Empty String confusion; Positive and Natural
Date: Tue, 30 Nov 2021 08:21:28 +0000
Organization: Aioe.org NNTP Server
Message-ID: <lytufuvyt3.fsf@pushface.org>
References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
<nnd$23404336$0a486277@9b8ca000aec60c20>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="43322"; posting-host="8nKyDL3nVTTIdBB8axZhRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (darwin)
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:itvtFY15bSgZykc0oai+RTVIAto=
 by: Simon Wright - Tue, 30 Nov 2021 08:21 UTC

ldries46 <bertus.dries@planet.nl> writes:

> Empty_String : Unbounded_String := To_Unbounded_String("");

* Given the name, you should probably declare it constant.

* You don't need to initialize it, ARM 4.5(73) [1] says "If an object of
type Unbounded_String is not otherwise initialized, it will be
initialized to the same value as Null_Unbounded_String".

* Ada.Strings.Unbounded.Null_Unbounded_String is a constant empty
string.

[1] http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-A-4-5.html#p73

Re: Empty String confusion; Positive and Natural

<lypmqivyfc.fsf@pushface.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!8nKyDL3nVTTIdBB8axZhRA.user.46.165.242.75.POSTED!not-for-mail
From: sim...@pushface.org (Simon Wright)
Newsgroups: comp.lang.ada
Subject: Re: Empty String confusion; Positive and Natural
Date: Tue, 30 Nov 2021 08:29:43 +0000
Organization: Aioe.org NNTP Server
Message-ID: <lypmqivyfc.fsf@pushface.org>
References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
<j0kndlFnvleU1@mid.individual.net>
<bea93bf3-f282-4e9b-8806-2b956d58fe51n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="50288"; posting-host="8nKyDL3nVTTIdBB8axZhRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (darwin)
Cancel-Lock: sha1:8QGHttNaSFUEBdsRxleMBgoa5/4=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Simon Wright - Tue, 30 Nov 2021 08:29 UTC

Kevin Chadwick <kevc3no4@gmail.com> writes:

>> It would clarify your question if you would show the declaration of
>> that record type. Does it use the String type, or the
>> Unbounded_String type?
>
> Hopefully I will have a doh moment when I get into the office in the
> morning and post code. I am getting a range check exception when I
> assign "" to a standard.String in a record by returning the record
> from a function. Surely, I must have caused it somehow.

If you declare S : String (1 .. 5) and you want to assign a string "foo"
to the whole of S you are forbidden to do so by the language: you have
to assign 5 characters, no more, no fewer.

This can be a royal pain, so we have Ada.Strings.Bounded (if you know
the maximum length) or .Unbounded (if you don't, and can afford more
overhead), both of which support variable-length strings.

Re: Empty String confusion; Positive and Natural

<j0m61gF1p4jU1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.h...@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: Empty String confusion; Positive and Natural
Date: Tue, 30 Nov 2021 10:34:56 +0200
Organization: Tidorum Ltd
Lines: 28
Message-ID: <j0m61gF1p4jU1@mid.individual.net>
References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
<j0kndlFnvleU1@mid.individual.net>
<bea93bf3-f282-4e9b-8806-2b956d58fe51n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net aqIKDf7UfbkDE3Ze+FWzoQ9OljRS20jozpKbR6OPwXh5HyLMrH
Cancel-Lock: sha1:sT+APXlOFw3L7/riESajLvXGvrQ=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0)
Gecko/20100101 Thunderbird/78.14.0
In-Reply-To: <bea93bf3-f282-4e9b-8806-2b956d58fe51n@googlegroups.com>
Content-Language: en-US
 by: Niklas Holsti - Tue, 30 Nov 2021 08:34 UTC

On 2021-11-30 0:50, Kevin Chadwick wrote:
>> It would clarify your question if you would show the declaration of that
>> record type. Does it use the String type, or the Unbounded_String type?
>
> Hopefully I will have a doh moment when I get into the office in the
> morning and post code. I am getting a range check exception when I
> assign "" to a standard.String

Although Standard.String is an unconstrained array type (that is, its
index range is defined as "Positive range <>"), every object of this
type is constrained to a fixed length, set when the object is created.

So if you have, for example:

S : String (1 .. 10);

then S'Length is always 10. If you try to assign to S a string of a
different length, for example "", you will get an exception because the
lengths do not match.

If you want a string object that is flexible in terms of length, you
should use the type Ada.Strings.Unbounded.Unbounded_String, or make an
instance of Ada.Strings.Bounded.Bounded_String with a suitable maximum
length.

Or you could use a fixed-length string but always pad it with blanks (or
whatever) up to the fixed length -- see Ada.Strings.Fixed for several
useful operations on such strings. Depends on what you want...

Re: Empty String confusion; Positive and Natural

<so4snd$s9c$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: spam.jrc...@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: Empty String confusion; Positive and Natural
Date: Tue, 30 Nov 2021 11:00:11 +0100
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <so4snd$s9c$1@dont-email.me>
References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
<j0kndlFnvleU1@mid.individual.net>
<bea93bf3-f282-4e9b-8806-2b956d58fe51n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 30 Nov 2021 10:00:13 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="e84dcf9151b9b5bb6beb5722472b0fe1";
logging-data="28972"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9IIX7IiBzsfjh9QDuy9h6g7dTIysZfH4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.3.1
Cancel-Lock: sha1:zNIO3jvOQQyfFqz+DL98O89w6h0=
In-Reply-To: <bea93bf3-f282-4e9b-8806-2b956d58fe51n@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R.Carter - Tue, 30 Nov 2021 10:00 UTC

On 2021-11-29 23:50, Kevin Chadwick wrote:
>
> Hopefully I will have a doh moment when I get into the office in the morning and post code. I am getting a range check exception when I assign "" to a standard.String in a record by returning the record from a function. Surely, I must have caused it somehow.

It sounds as if you think type String is magic. String is a
one-dimensional array type, no different than any other one-dimensional
array type. It is declared in ARM A.1(37/3)
(http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-A-1.html) as

type String is array(Positive range <>) of Character
with Pack;

If you think that

type T is array (Positive range <>) of Integer;
V : T (1 .. 5);
....
V := (1 .. 0 => <>);

should work, then you don't understand arrays in Ada.

If you understand why that won't work, then

S : String (1 .. 5);
....
S := "";

is the exact same thing and fails in the same way for the same reason.

--
Jeff Carter
"I did not rob a bank. If I'd robbed a bank, everything
would be great. I tried to rob a bank, is what happened,
and they got me. I misspelled the note."
Take the Money and Run
140

Re: Empty String confusion; Positive and Natural

<eac0b8bd-7f64-4909-b0d3-7730bc86a1efn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ad4:5aeb:: with SMTP id c11mr37174361qvh.69.1638274639618;
Tue, 30 Nov 2021 04:17:19 -0800 (PST)
X-Received: by 2002:a25:7613:: with SMTP id r19mr41015615ybc.498.1638274639482;
Tue, 30 Nov 2021 04:17:19 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.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: Tue, 30 Nov 2021 04:17:19 -0800 (PST)
In-Reply-To: <so4snd$s9c$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=92.40.187.174; posting-account=5K6RMgoAAADQeoHIOMi2dg5aYc0IVxGi
NNTP-Posting-Host: 92.40.187.174
References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
<j0kndlFnvleU1@mid.individual.net> <bea93bf3-f282-4e9b-8806-2b956d58fe51n@googlegroups.com>
<so4snd$s9c$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <eac0b8bd-7f64-4909-b0d3-7730bc86a1efn@googlegroups.com>
Subject: Re: Empty String confusion; Positive and Natural
From: kevc3...@gmail.com (Kevin Chadwick)
Injection-Date: Tue, 30 Nov 2021 12:17:19 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 19
 by: Kevin Chadwick - Tue, 30 Nov 2021 12:17 UTC

I have a create function that returns a type RunOutput

I always get range check failed even with a string of multiple characters.

type RunOutput(LogLen, OutputLen : Natural) is record
LogStr : String(0..LogLen);
Output : String(0..OutputLen);
....
end record;

I did have the following which works, so long as the string is not empty

type RunOutput(LogLen, OutputLen : Positive) is record
LogStr : String(1..LogLen);
Output : String(1..OutputLen);
....
end record;

P.s. I am not using exceptions with messages for log strings because I would rather use features that work with the zero footprint runtime as much as possible, where it makes sense.

Re: Empty String confusion; Positive and Natural

<nnd$1d39ac24$50e63d55@24a051383f433873>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Date: Tue, 30 Nov 2021 13:39:28 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Subject: Re: Empty String confusion; Positive and Natural
Content-Language: en-GB
Newsgroups: comp.lang.ada
References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
<nnd$23404336$0a486277@9b8ca000aec60c20> <lytufuvyt3.fsf@pushface.org>
From: bertus.d...@planet.nl (ldries46)
In-Reply-To: <lytufuvyt3.fsf@pushface.org>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <nnd$1d39ac24$50e63d55@24a051383f433873>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe003.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 19
Injection-Date: Tue, 30 Nov 2021 13:39:28 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 1665
 by: ldries46 - Tue, 30 Nov 2021 12:39 UTC

Op 30-11-2021 om 9:21 schreef Simon Wright:
> ldries46 <bertus.dries@planet.nl> writes:
>
>> Empty_String : Unbounded_String := To_Unbounded_String("");
> * Given the name, you should probably declare it constant.
>
> * You don't need to initialize it, ARM 4.5(73) [1] says "If an object of
> type Unbounded_String is not otherwise initialized, it will be
> initialized to the same value as Null_Unbounded_String".
>
> * Ada.Strings.Unbounded.Null_Unbounded_String is a constant empty
> string.
>
> [1] http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-A-4-5.html#p73
You are right. it should be

Empty_String : constant Unbounded_String := To_Unbounded_String("");

Re: Empty String confusion; Positive and Natural

<so56to$1t8$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ros...@adalog.fr (J-P. Rosen)
Newsgroups: comp.lang.ada
Subject: Re: Empty String confusion; Positive and Natural
Date: Tue, 30 Nov 2021 13:54:16 +0100
Organization: Adalog
Lines: 39
Message-ID: <so56to$1t8$1@dont-email.me>
References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
<j0kndlFnvleU1@mid.individual.net>
<bea93bf3-f282-4e9b-8806-2b956d58fe51n@googlegroups.com>
<so4snd$s9c$1@dont-email.me>
<eac0b8bd-7f64-4909-b0d3-7730bc86a1efn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 30 Nov 2021 12:54:16 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0e8ddcdce013eb64e6ce28584cebcb32";
logging-data="1960"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18IMfVraNVr9bQAZFHrLswZ"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:Mum8RxH7/SC1H8JuGhZivxjBPsI=
In-Reply-To: <eac0b8bd-7f64-4909-b0d3-7730bc86a1efn@googlegroups.com>
Content-Language: fr
 by: J-P. Rosen - Tue, 30 Nov 2021 12:54 UTC

Le 30/11/2021 à 13:17, Kevin Chadwick a écrit :
> I have a create function that returns a type RunOutput
>
> I always get range check failed even with a string of multiple characters.
>
> type RunOutput(LogLen, OutputLen : Natural) is record
> LogStr : String(0..LogLen);
> Output : String(0..OutputLen);
> ...
> end record;
>
> I did have the following which works, so long as the string is not empty
>
> type RunOutput(LogLen, OutputLen : Positive) is record
> LogStr : String(1..LogLen);
> Output : String(1..OutputLen);
> ...
> end record;
>
>
> P.s. I am not using exceptions with messages for log strings because I would rather use features that work with the zero footprint runtime as much as possible, where it makes sense.
>
Since String is indexed by Positive (not Natural), the lower bound
cannot be 0. OTOH, there is no check for bounds of empty arrays,
therefore the following would work:

type RunOutput(LogLen, OutputLen : Natural) is record
LogStr : String(1..LogLen);
Output : String(1..OutputLen);

and you can have empty strings if Loglen or Outputlen is 0, without
Constraint_Error. (It's precisely for that reason that there is no check
of bounds of empty arrays).
--
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52
https://www.adalog.fr

Re: Empty String confusion; Positive and Natural

<14ff2180-6e3b-40a0-bdab-1d812826f091n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:622a:180c:: with SMTP id t12mr43488223qtc.507.1638277950355;
Tue, 30 Nov 2021 05:12:30 -0800 (PST)
X-Received: by 2002:a25:b8c7:: with SMTP id g7mr41723684ybm.115.1638277950171;
Tue, 30 Nov 2021 05:12:30 -0800 (PST)
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: Tue, 30 Nov 2021 05:12:29 -0800 (PST)
In-Reply-To: <so56to$1t8$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=84.92.86.82; posting-account=5K6RMgoAAADQeoHIOMi2dg5aYc0IVxGi
NNTP-Posting-Host: 84.92.86.82
References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>
<j0kndlFnvleU1@mid.individual.net> <bea93bf3-f282-4e9b-8806-2b956d58fe51n@googlegroups.com>
<so4snd$s9c$1@dont-email.me> <eac0b8bd-7f64-4909-b0d3-7730bc86a1efn@googlegroups.com>
<so56to$1t8$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <14ff2180-6e3b-40a0-bdab-1d812826f091n@googlegroups.com>
Subject: Re: Empty String confusion; Positive and Natural
From: kevc3...@gmail.com (Kevin Chadwick)
Injection-Date: Tue, 30 Nov 2021 13:12:30 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Kevin Chadwick - Tue, 30 Nov 2021 13:12 UTC

> Since String is indexed by Positive (not Natural), the lower bound
> cannot be 0. OTOH, there is no check for bounds of empty arrays,
> therefore the following would work:
> type RunOutput(LogLen, OutputLen : Natural) is record
> LogStr : String(1..LogLen);
> Output : String(1..OutputLen);
>
> and you can have empty strings if Loglen or Outputlen is 0, without
> Constraint_Error. (It's precisely for that reason that there is no check
> of bounds of empty arrays).

I See,
Thanks everyone

I apologise for posting the original thread whilst leaving the office and
posting without the code upfront.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor