From: mab@wdl39.wdl.loral.com (Mark A Biggar)
Subject: Re: Membership in "set" of characters
Date: Fri, 19 Mar 1993 19:57:12 GMT
Date: 1993-03-19T19:57:12+00:00 [thread overview]
Message-ID: <1993Mar19.195712.9187@wdl.loral.com> (raw)
In-Reply-To: J6QBBP3L@math.fu-berlin.de
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
okay := affirmatives'VALUE(CHARACTER'IMAGE(ch)) in affirmatives;
and even this may not work because not all values of type CHARACTER have
a 'IMAGE.
A much better method of doing this in Ada is to use a table lookup like so:
type CHAR_SET is array(CHARACTER) of BOOLEAN;
AFFIRMATIVES : CHAR_SET := CHAR_SET'('y'|'Y'|'j'|'J'|'o'|'O' => TRUE,
others => FALSE);
then use the following for the test
okay := AFFIRMATIVES(ch);
--
Mark Biggar
mab@wdl1.wdl.loral.com
next prev parent reply other threads:[~1993-03-19 19:57 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 [this message]
1993-03-22 10:37 ` Andrew Dunstan,,2285592,
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