Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"When in doubt, print 'em out." -- Karl's Programming Proverb 0x7


devel / comp.lang.ada / Re: Is there a way to see if a value is declared as a constant

SubjectAuthor
* Is there a way to see if a value is declared as a constantldries46
+- Re: Is there a way to see if a value is declared as a constantBjörn Lundin
+- Re: Is there a way to see if a value is declared as a constantJeffrey R. Carter
+- Re: Is there a way to see if a value is declared as a constantDmitry A. Kazakov
+* Re: Is there a way to see if a value is declared as a constantldries46
|`- Re: Is there a way to see if a value is declared as a constantEmmanuel Briot
+- Re: Is there a way to see if a value is declared as a constantShark8
`- Re: Is there a way to see if a value is declared as a constantldries46

1
Is there a way to see if a value is declared as a constant

<nnd$38993e8c$31c2bc63@28832d745e09e0f7>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Newsgroups: comp.lang.ada
X-Mozilla-News-Host: news://news.kpn.nl:119
From: bertus.d...@planet.nl (ldries46)
Subject: Is there a way to see if a value is declared as a constant
Date: Mon, 13 Sep 2021 19:08:59 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Content-Language: en-GB
Message-ID: <nnd$38993e8c$31c2bc63@28832d745e09e0f7>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.mixmin.net!feed.abavia.com!abe002.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 26
Injection-Date: Mon, 13 Sep 2021 19:09:00 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: ldries46 - Mon, 13 Sep 2021 17:08 UTC

I have a set of constants that need a different name each for
readability. It may not be an array.
For instance:
C1 : constant record_item := .....
C2 : constant record_item := .....
C3 : constant record_item := .....
C4 : constant record_item := .....
C5 : constant record_item := .....

Now in a procedure or a function I have to use one of these constants
for instance:

function X(C : record_item) return record_Item is
   RI : record_item;
begin
   ..
   ..
   RI := C -- This C may only be one of the five constants and not
another record_item
   ..
   ..
    return RI;
end X;

In what way do I test if C is a constant and not another record Item

Re: Is there a way to see if a value is declared as a constant

<sho1me$jf5$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: b.f.lun...@gmail.com (Björn Lundin)
Newsgroups: comp.lang.ada
Subject: Re: Is there a way to see if a value is declared as a constant
Date: Mon, 13 Sep 2021 19:27:42 +0200
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <sho1me$jf5$1@dont-email.me>
References: <nnd$38993e8c$31c2bc63@28832d745e09e0f7>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 13 Sep 2021 17:27:42 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b17da7d541f611871e25504600636075";
logging-data="19941"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+M/eMHHke+wQkIVFdzQdsx"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:78.0)
Gecko/20100101 Thunderbird/78.14.0
Cancel-Lock: sha1:W68j552jjNyUWbw5Ln4pOFSNF68=
In-Reply-To: <nnd$38993e8c$31c2bc63@28832d745e09e0f7>
Content-Language: sv
 by: Björn Lundin - Mon, 13 Sep 2021 17:27 UTC

Den 2021-09-13 kl. 19:08, skrev ldries46:
> I have a set of constants that need a different name each for
> readability. It may not be an array.
> For instance:
> C1 : constant record_item := .....
> C2 : constant record_item := .....
> C3 : constant record_item := .....
> C4 : constant record_item := .....
> C5 : constant record_item := .....

Two approaches - but both uses arrays.
You don't say why (more that readability) you don't want array.

If it is because integer idexing you can skip that and
put the values in an array, using a
readable index type

eg (for placing bets at Betfair - football/soccer

type Bet_Market_Type is (Match_Odds,
Correct_Score,
Half_Time_Score,
Hat_Tricked_Scored,
Penalty_Taken,
Sending_Off);

Market : array (Bet_Market_Type'range) of record_item := (...);

use as

Market(Correct_Score) := ...

or
put the values in an array.
Let constants rename item in array

use constants in code

check RI in array

>
> Now in a procedure or a function I have to use one of these constants
> for instance:
>
> function X(C : record_item) return record_Item is
>    RI : record_item;
> begin
>    ..
>    ..
>    RI := C -- This C may only be one of the five constants and not
> another record_item
>    ..
>    ..
>     return RI;
> end X;
>
> In what way do I test if C is a constant and not another record Item

--
Björn

Re: Is there a way to see if a value is declared as a constant

<sho6ea$t51$1@dont-email.me>

  copy mid

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

  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.not.acm.org (Jeffrey R. Carter)
Newsgroups: comp.lang.ada
Subject: Re: Is there a way to see if a value is declared as a constant
Date: Mon, 13 Sep 2021 20:48:40 +0200
Organization: Also freenews.netfront.net; news.tornevall.net;
news.eternal-september.org
Lines: 19
Message-ID: <sho6ea$t51$1@dont-email.me>
References: <nnd$38993e8c$31c2bc63@28832d745e09e0f7>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 13 Sep 2021 18:48:42 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7f8b54b110af01c1b098dacc1fee8aab";
logging-data="29857"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Wk0V03kObAB3LV2XuPTpegbJ9zWd4M30="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:ZypVPceG5QDza6y9InTuuKPgSE4=
In-Reply-To: <nnd$38993e8c$31c2bc63@28832d745e09e0f7>
Content-Language: en-US
 by: Jeffrey R. Carter - Mon, 13 Sep 2021 18:48 UTC

On 9/13/21 7:08 PM, ldries46 wrote:
>
> In what way do I test if C is a constant and not another record Item

function X (C : in Record_Item) return Record_Item with
Pre => C = C1 or C = C2 or C = C3 or C = C4 or C = C5;

Of course, if you have a lot of constants with more descriptive names, the
precondition will be hard to read. If you had a constant array it would be more
readable:

Pre => (for some A of Allowed_Values => C = A);

--
Jeff Carter
"You've got the brain of a four-year-old boy,
and I bet he was glad to get rid of it."
Horse Feathers
47

Re: Is there a way to see if a value is declared as a constant

<sho74p$ucg$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!Hx95GBhnJb0Xc8StPhH8AA.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Is there a way to see if a value is declared as a constant
Date: Mon, 13 Sep 2021 21:00:45 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sho74p$ucg$1@gioia.aioe.org>
References: <nnd$38993e8c$31c2bc63@28832d745e09e0f7>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="31120"; posting-host="Hx95GBhnJb0Xc8StPhH8AA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Mon, 13 Sep 2021 19:00 UTC

On 2021-09-13 19:08, ldries46 wrote:
> I have a set of constants that need a different name each for
> readability. It may not be an array.
> For instance:
> C1 : constant record_item := .....
> C2 : constant record_item := .....
> C3 : constant record_item := .....
> C4 : constant record_item := .....
> C5 : constant record_item := .....
>
> Now in a procedure or a function I have to use one of these constants
> for instance:
>
> function X(C : record_item) return record_Item is
>    RI : record_item;
> begin
>    ..
>    ..
>    RI := C -- This C may only be one of the five constants and not
> another record_item
>    ..
>    ..
>     return RI;
> end X;
>
> In what way do I test if C is a constant and not another record Item

[The requirement makes no sense and suggests design error]

type Record_Item is tagged record
I : Integer;
end record;
...

type Dedicated_Record_Item is new Record_Item with null record;
C1 : constant Dedicated_Record_Item := (I => 1);
C2 : constant Dedicated_Record_Item := (I => 2);
C3 : constant Dedicated_Record_Item := (I => 3);
C4 : constant Dedicated_Record_Item := (I => 4);
C5 : constant Dedicated_Record_Item := (I => 5);

function X (C : Dedicated_Record_Item) return Record_Item is
begin
return RI : Record_Item := Record_Item (C);
end X;

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Is there a way to see if a value is declared as a constant

<nnd$06effbf5$6aa68ebd@010391d1f6c084ba>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Subject: Re: Is there a way to see if a value is declared as a constant
Newsgroups: comp.lang.ada
References: <nnd$38993e8c$31c2bc63@28832d745e09e0f7>
From: bertus.d...@planet.nl (ldries46)
Date: Tue, 14 Sep 2021 08:47:17 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
MIME-Version: 1.0
In-Reply-To: <nnd$38993e8c$31c2bc63@28832d745e09e0f7>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Content-Language: en-GB
Message-ID: <nnd$06effbf5$6aa68ebd@010391d1f6c084ba>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe001.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 40
Injection-Date: Tue, 14 Sep 2021 08:47:17 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2448
 by: ldries46 - Tue, 14 Sep 2021 06:47 UTC

Op 13-9-2021 om 19:08 schreef ldries46:
> I have a set of constants that need a different name each for
> readability. It may not be an array.
> For instance:
> C1 : constant record_item := .....
> C2 : constant record_item := .....
> C3 : constant record_item := .....
> C4 : constant record_item := .....
> C5 : constant record_item := .....
>
> Now in a procedure or a function I have to use one of these constants
> for instance:
>
> function X(C : record_item) return record_Item is
>    RI : record_item;
> begin
>    ..
>    ..
>    RI := C -- This C may only be one of the five constants and not
> another record_item
>    ..
>    ..
>     return RI;
> end X;
>
> In what way do I test if C is a constant and not another record Item
The reason I want this construction is that it is part of a reusable
package where one of the functions may only use a constant.
That function is a kind of initiation function that the end user should
use in his/her end program.
I hoped there would be an attribute that shows if the item is a constant
and that I want to be be tested. The only simple way I know at this
moment is adding a boolean to the record that can be tested but that
means that that boolean may not be reached by the the program  that uses
the package, so only that boolean should be (limited) private.
The reason that I do not want to use an array is that however the record
and the functions used on these records are all the same, the physical
items  are different. Not using an array means that the readability of
the of the package will be better.

Re: Is there a way to see if a value is declared as a constant

<38d17a31-ef3a-4ff0-a05c-89a05c9d7e06n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ae9:f304:: with SMTP id p4mr3567199qkg.334.1631602699284;
Mon, 13 Sep 2021 23:58:19 -0700 (PDT)
X-Received: by 2002:a25:af49:: with SMTP id c9mr16957525ybj.432.1631602698803;
Mon, 13 Sep 2021 23:58:18 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.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, 13 Sep 2021 23:58:18 -0700 (PDT)
In-Reply-To: <nnd$06effbf5$6aa68ebd@010391d1f6c084ba>
Injection-Info: google-groups.googlegroups.com; posting-host=87.88.29.208; posting-account=6yLzewoAAABoisbSsCJH1SPMc9UrfXBH
NNTP-Posting-Host: 87.88.29.208
References: <nnd$38993e8c$31c2bc63@28832d745e09e0f7> <nnd$06effbf5$6aa68ebd@010391d1f6c084ba>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <38d17a31-ef3a-4ff0-a05c-89a05c9d7e06n@googlegroups.com>
Subject: Re: Is there a way to see if a value is declared as a constant
From: briot.em...@gmail.com (Emmanuel Briot)
Injection-Date: Tue, 14 Sep 2021 06:58:19 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 9
 by: Emmanuel Briot - Tue, 14 Sep 2021 06:58 UTC

> items are different. Not using an array means that the readability of
> the of the package will be better.

It won't, really. If you follow Bjorn's suggestion of using an enumeration type (user visible)
and an array (in the body of your package, to get the associated constant), you have a very
readable package, where users can only use one of your enumeration literals.

With the approach you are trying to put in place, users could define their own constants that
doesn't match the ones you provide. They would still be "constant", so even if it was possible
to write a test like you were looking for, that test would pass.

Re: Is there a way to see if a value is declared as a constant

<33ca979b-c486-44c9-a34d-871fdfe1d568n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a37:a51:: with SMTP id 78mr7471648qkk.88.1631663242196;
Tue, 14 Sep 2021 16:47:22 -0700 (PDT)
X-Received: by 2002:a5b:b04:: with SMTP id z4mr2021435ybp.457.1631663241892;
Tue, 14 Sep 2021 16:47:21 -0700 (PDT)
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, 14 Sep 2021 16:47:21 -0700 (PDT)
In-Reply-To: <nnd$38993e8c$31c2bc63@28832d745e09e0f7>
Injection-Info: google-groups.googlegroups.com; posting-host=146.5.2.231; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC
NNTP-Posting-Host: 146.5.2.231
References: <nnd$38993e8c$31c2bc63@28832d745e09e0f7>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <33ca979b-c486-44c9-a34d-871fdfe1d568n@googlegroups.com>
Subject: Re: Is there a way to see if a value is declared as a constant
From: onewinge...@gmail.com (Shark8)
Injection-Date: Tue, 14 Sep 2021 23:47:22 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 21
 by: Shark8 - Tue, 14 Sep 2021 23:47 UTC

When you start fighting the language, it's usually an indicator that your design needs changing.
Try using the things Ada does (e.g. types) to model your problem-space.

Package Example is
Type Whatever is private;
I, J, K : Constant Whatever;
Private
Type Whatever is new Integer;
Type Constants is Array (Positive range <>) of Whatever
with Dynamic_Predicate =>
(for all Index_1 in Constants'First..Natural'Pred(Constants'Last) =>
(for all Index_2 in Positive'Succ(Index_1)..Constants'Last =>
Constants(Index_1) /= Constants(Index_2)
)
);

Constant_Store : Constant Constants:= (1,7,3,11,77,2,7);

I : Constant Whatever:= Constant_Store(4);
J : Constant Whatever:= Constant_Store(2);
K : Constant Whatever:= Constant_Store(5);
End Example;

Re: Is there a way to see if a value is declared as a constant

<nnd$32625521$73c3d8da@cb0786dc2fdce31d>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Subject: Re: Is there a way to see if a value is declared as a constant
Newsgroups: comp.lang.ada
References: <nnd$38993e8c$31c2bc63@28832d745e09e0f7>
From: bertus.d...@planet.nl (ldries46)
Date: Sat, 18 Sep 2021 07:54:09 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
MIME-Version: 1.0
In-Reply-To: <nnd$38993e8c$31c2bc63@28832d745e09e0f7>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Content-Language: en-GB
Message-ID: <nnd$32625521$73c3d8da@cb0786dc2fdce31d>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.mixmin.net!feed.abavia.com!abe001.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 30
Injection-Date: Sat, 18 Sep 2021 07:54:10 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: ldries46 - Sat, 18 Sep 2021 05:54 UTC

Op 13-9-2021 om 19:08 schreef ldries46:
> I have a set of constants that need a different name each for
> readability. It may not be an array.
> For instance:
> C1 : constant record_item := .....
> C2 : constant record_item := .....
> C3 : constant record_item := .....
> C4 : constant record_item := .....
> C5 : constant record_item := .....
>
> Now in a procedure or a function I have to use one of these constants
> for instance:
>
> function X(C : record_item) return record_Item is
>    RI : record_item;
> begin
>    ..
>    ..
>    RI := C -- This C may only be one of the five constants and not
> another record_item
>    ..
>    ..
>     return RI;
> end X;
>
> In what way do I test if C is a constant and not another record Item
In the meantime I have added a boolean to the record "record_item"in
which true means this is a constant and false  this not a constant then
in the function X  I raise an exception if that boolean if false

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor