comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@mitre-bedford.arpa  (Robert I. Eachus)
Subject: Re: Character Type Definition
Date: 24 Jul 91 23:16:39 GMT	[thread overview]
Message-ID: <EACHUS.91Jul24161639@largo.mitre.org> (raw)

In article <rbaldwin.680294862@galaxy.afit.af.mil> 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...

             reply	other threads:[~1991-07-24 23:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-07-24 23:16 Robert I. Eachus [this message]
  -- strict thread matches above, loose matches on Subject: below --
1991-07-29  7:56 Character Type Definition Robert I. Eachus
1991-07-23 18:47 cis.ohio-state.edu!udecc.engr.udayton.edu!blackbird.afit.af.mil!galaxy.af
replies disabled

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