comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
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	[thread overview]
Message-ID: <sho74p$ucg$1@gioia.aioe.org> (raw)
In-Reply-To: nnd$38993e8c$31c2bc63@28832d745e09e0f7

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

  parent reply	other threads:[~2021-09-13 19:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-13 17:08 Is there a way to see if a value is declared as a constant ldries46
2021-09-13 17:27 ` Björn Lundin
2021-09-13 18:48 ` Jeffrey R. Carter
2021-09-13 19:00 ` Dmitry A. Kazakov [this message]
2021-09-14  6:47 ` ldries46
2021-09-14  6:58   ` Emmanuel Briot
2021-09-14 23:47 ` Shark8
2021-09-18  5:54 ` ldries46
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox