From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 24 Jul 91 23:16:39 GMT From: eachus@mitre-bedford.arpa (Robert I. Eachus) Subject: Re: Character Type Definition Message-ID: List-Id: In article news@afit.af.mil writes: > I am new to Ada and have been trying to find out how to do the following. > I would like to define a character type of disjoint ASCII characters so I > can perform a membership test... Since the set you need is not contiguous you need a Set construct. If you don't have a generic Set package around ;-) all you need do is: type Character_Set is array (Character) of Boolean; pragma PACK(Character_Set); Now for your example the code is: Math_Operator: constant Character_Set := ('^' | '*' | '/' | '+' | '-' => True, others => False); ... if Math_Operator(My_Operator) then... Depending on the size and use of the sets you may or may not want the pragma PACK. While this is not quite as elegant as having a set type in Ada, in was felt to be easy enough that adding sets was not justified. Without actually benchmarking things in particular cases, it is almost impossible to tell whether this, an if statement with "'^' or '*' or '+'..." or the case statement will be faster. However the set method is in general the easiest to work with and the least error prone. Where a set is contiguous in ASCII you may want to use subtypes. If the code needs to be portable or will be around a long time, this is not a good idea. The set model is ALWAYS the easiest to maintain. -- Robert I. Eachus with STANDARD_DISCLAIMER; use STANDARD_DISCLAIMER; function MESSAGE (TEXT: in CLEVER_IDEAS) return BETTER_IDEAS is...