[comp.lang.pascal] Enumeration Inverse- was Request : Help with E Types

g_harrison@vger.nsu.edu (12/11/90)

In article <1990Dec10.180345.31492@wpi.WPI.EDU>, kamal@wpi.WPI.EDU (Kamal Z Zamli) writes:
> In article <3983@uniol.UUCP> Arne.Gehlhaar@arbi.informatik.uni-oldenburg.de (Arne Gehlhaar) writes:

I am familiar with several versions of Pascal extensions and believe that those
with enumeration IO facilities are providing important functionality.  I have a
different "complaint."  

When working with CHAR type we have CHR as the inverse of ORD.  With general
enumerated types we don't.  

For example in Ada there is

type FUZZY = (YES, NO, MAYBE);

F : FUZZY := NO;

FUZZY'POS(F) is 1
FUZZY'VAL(1) is NO

FUZZY'POS(FUZZY'VAL(2)) is 2
FUZZY'VAL(FUZZY'POS(MAYBE)) is MAYBE

We can certainly find the Nth (N = 0...) element in an enumerated type in
Pascal by searching for it, but are there some tricks (Machine-Dependent or
otherwise) to provide an inverse to ORD that do not involve searching?

George....

------------------------------------------------------*------o    Happy---
-- George C. Harrison ------------------------------ * * ----o_o___ New---
----- Professor of Computer Science --------------  * * * ----\ o /-Year--
----- Norfolk State University, -----------------  *Merry* ----\ /--------
-------- Norfolk, Virginia 23504 ---------------  * * * * * ----|---------
----- INTERNET:  g_harrison@vger.nsu.edu ------  *Christmas* --_|_--------
----------These are MY views.... you may share them..*** -----------------

kincaid@mpccl.ksu.edu (Joe Kincaid) (12/13/90)

In article <357.27648291@vger.nsu.edu> g_harrison@vger.nsu.edu writes:
>In article <1990Dec10.180345.31492@wpi.WPI.EDU>, kamal@wpi.WPI.EDU (Kamal Z Zamli) writes:
>> In article <3983@uniol.UUCP> Arne.Gehlhaar@arbi.informatik.uni-oldenburg.de (Arne Gehlhaar) writes:
>
>I am familiar with several versions of Pascal extensions and believe that those
>with enumeration IO facilities are providing important functionality.  I have a
>different "complaint."  
>
>When working with CHAR type we have CHR as the inverse of ORD.  With general
>enumerated types we don't.  
>
>For example in Ada there is
>
>    [...]
>
>We can certainly find the Nth (N = 0...) element in an enumerated type in
>Pascal by searching for it, but are there some tricks (Machine-Dependent or
>otherwise) to provide an inverse to ORD that do not involve searching?
>
>George....
>

I usually use typecasting to achieve this.  It works in Turbo anyway and
you should probably check to be sure the '0' element lines up where you think
it does.

Here's an example from pg 528 of the Turbo Pascal 4.0 manual:

    "In version 3.0, you had to use the _Move_ function to copy data from one
data structure to another if the structures were not assignment-compatible:

[...Example omitted...]

"The exception was for ordinal data types (char, byte, integer, boolean, 
enumerated types), in which case you use retyping (typecasting):

   IntVar   := byte('a');
   MonthVar := Month(3);

"In version 4.0, typecasting has been extended to all types, with the
requirement that the source and destination be exactly the same size:

[...Example (and the rest) omitted...]


--
Joseph Kincaid                 |  All the views contained herein are my own.
kincaid@einstein.mpccl.ksu.edu |  Everything else I share with my wife.
KSU - Mathematics Department   |  Come to think, those are probably hers, too.

g_harrison@vger.nsu.edu (12/13/90)

In article <1990Dec13.033609.15385@maverick.ksu.ksu.edu>, kincaid@mpccl.ksu.edu (Joe Kincaid) writes:
> In article <357.27648291@vger.nsu.edu> g_harrison@vger.nsu.edu writes:
>>In article <1990Dec10.180345.31492@wpi.WPI.EDU>, kamal@wpi.WPI.EDU (Kamal Z Zamli) writes:
>>> In article <3983@uniol.UUCP> Arne.Gehlhaar@arbi.informatik.uni-oldenburg.de (Arne Gehlhaar) writes:
>>

[some of my babble deleted]

>>We can certainly find the Nth (N = 0...) element in an enumerated type in
>>Pascal by searching for it, but are there some tricks (Machine-Dependent or
>>otherwise) to provide an inverse to ORD that do not involve searching?
>>
>>George....
>>
> 
> I usually use typecasting to achieve this.  It works in Turbo anyway and
> you should probably check to be sure the '0' element lines up where you think
> it does.
> 
[Joseph's further stuff deleted]
> Joseph Kincaid                 |  All the views contained herein are my own.
> kincaid@einstein.mpccl.ksu.edu |  Everything else I share with my wife.
> KSU - Mathematics Department   |  Come to think, those are probably hers, too.

I sincerely thank all who have replied and followed up on my question about a
functional inverse to ORD.  The answer was always "typecasting."  

George......

------------------------------------------------------*------o    Happy---
-- George C. Harrison ------------------------------ * * ----o_o___ New---
----- Professor of Computer Science --------------  * * * ----\ o /-Year--
----- Norfolk State University, -----------------  *Merry* ----\ /--------
-------- Norfolk, Virginia 23504 ---------------  * * * * * ----|---------
----- INTERNET:  g_harrison@vger.nsu.edu ------  *Christmas* --_|_--------
----------These are MY views.... you may share them..*** -----------------