comp.lang.ada
 help / color / mirror / Atom feed
From: andrewd@eeyore.cs.adelaide.edu.au (Andrew Dunstan,,2285592,)
Subject: Re: Membership in "set" of characters
Date: 22 Mar 1993 10:37:48 GMT
Date: 1993-03-22T10:37:48+00:00	[thread overview]
Message-ID: <1ok4ts$3cv@huon.itd.adelaide.edu.au> (raw)
In-Reply-To: 1993Mar19.195712.9187@wdl.loral.com

From article <1993Mar19.195712.9187@wdl.loral.com>, by mab@wdl39.wdl.loral.com (Mark A Biggar):
> In article <J6QBBP3L@math.fu-berlin.de> dww@math.fu-berlin.de (Debora Weber-Wulff) writes:
>>with text_io; use text_io;
>>procedure muell3 is
>>type affirmatives is ('y', 'Y', 'j', 'J', 'o', 'O');
>>  ch : CHARACTER;
>>  okay : Boolean;
>>begin
>>  get (ch);
>>  -- The next statement gets flagged with
>>  -- type clash in membership test [LRM 4.5.2/10]
>>  okay := ch IN affirmatives;
>>end muell3;
> 
> The error message from the compiler is correct type CHARACTER clashes with
> type affirmatives.  The only way to do what you want is to cheat using 'value
> and 'image like so
>

The 'character' literals are not characters, but the (overloaded)
names of the values of an enumeration type. That is why there is a
type clash.

Better still, let's ask WHY you want to do this.

Are the affirmatives the only valid responses? If so, then use
enumeration_io and trap the exception data_error. 

If not, if any character value will do, use the approach already
suggested by Mark.

If the range of valid responses is more limited, decalre an
enumeration type with all the affirmative responses at one end and the
rest at the other end, and then declare affirmative as a subrange of
valid_responses. then get your response (using enumeration_io and
check to see if it is in the subrange.


cheers

andrew dunstan.
#######################################################################
#  Andrew Dunstan                   #   There's nothing good or bad   #
#  Department of Computer Science   #   but thinking makes it so.     #
#  University of Adelaide           #                                 #



  reply	other threads:[~1993-03-22 10:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-03-19 17:06 Membership in "set" of characters Debora Weber-Wulff
1993-03-19 19:57 ` Mark A Biggar
1993-03-22 10:37   ` Andrew Dunstan,,2285592, [this message]
1993-03-22 12:22     ` Debora Weber-Wulff
1993-03-22 17:11       ` Robert I. Eachus
1993-03-22 15:49   ` Ada 9X references M. Ramchandran
1993-03-22 21:50     ` Alex Blakemore
1993-03-23  4:16     ` Michael Feldman
replies disabled

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