From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Some kind of repeating in Static_Predicate
Date: Tue, 5 Jun 2018 15:37:30 -0500
Date: 2018-06-05T15:37:30-05:00 [thread overview]
Message-ID: <pf6saa$506$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: 675621d4-7f23-48bd-a7e0-4105b21ddfd7@googlegroups.com
"ytomino" <aghia05@gmail.com> wrote in message
news:675621d4-7f23-48bd-a7e0-4105b21ddfd7@googlegroups.com...
> On Tuesday, June 5, 2018 at 6:33:48 AM UTC+9, Randy Brukardt wrote:
...
>> > Thanks. But I want to separate the table and the subtype...
>>
>> That seems backwards to me. You are wanting to declare a set subtype, and
>> Ada uses the silly static predicate for doing so rather than having a
>> proper
>> set constraint. Either way, that's a subtype declaration.
>>
>> So the operative thing here is the subtype. There's no "table" in a set
>> description. If you need to check membership in the set, you just do that
>> with "in".
>>
>> Thus:
>>
>> subtype T is Character
>> with Static_Predicate => (T in 'T' | 'a' | 'b' | 'l' | 'e');
>>
>> if Param in T then ...
>>
>> If you really needed a table, I'd construct that from the set. (But I
>> can't
>> imagine what the use would be, certainly in cases like the "separators"
>> definition you showed in another mail.)
>
> Thanks. I understood it's backwards.
> Yes, the table is needless in run-time. I want only compile-time checking
>by Static_Predicate in this case. Also, types should be more primary than
>constants basically.
> However, a subtype declaration can't be separated to another package...
Of course a subtype can be declared in another package, I'm not sure why you
say that. For subtypes, you can always declare another subtype in your
primary package to get visibility:
package Params is
subtype Separators is Character with Static_Predicate => Separators
in '/' | '\';
-- other configuation parameters here.
end Params;
with Params;
package File_Ops is
subtype Separators is Params.Separators;
-- Other file operations here.
end File_Ops;
(Using the same exact name isn't a good idea if you are the sort to stick
use clauses everywhere,but of course the names don't have to be identical.)
Also note that "use type" and "use all type" will give you appropriate
visibility on the operators (and primitive operations, in the case of "use
all type") regardless of where the type is declared - another reason to
prefer "use type" when possible.
>The table may be configured before compiling, like the example of directory
>separators.
Yes, see above.
Randy.
next prev parent reply other threads:[~2018-06-05 20:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-03 17:45 Some kind of repeating in Static_Predicate ytomino
2018-06-04 6:26 ` Jacob Sparre Andersen
2018-06-04 7:15 ` ytomino
2018-06-04 21:33 ` Randy Brukardt
2018-06-05 2:30 ` ytomino
2018-06-05 20:37 ` Randy Brukardt [this message]
2018-06-04 7:17 ` ytomino
2018-06-06 11:04 ` Marius Amado-Alves
2018-06-06 14:53 ` ytomino
2018-06-07 9:15 ` Marius Amado-Alves
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox