from ORD to CARDINAL to CONVERT 
Author Message
 from ORD to CARDINAL to CONVERT


Quote:
> Why not define ORD(aValueOfIntType) to be CARDINAL(aValueOfIntType)?
> That is, a meaning-preserving coercion into type CARDINAL?  That way,
> you could just get rid of ORD altogether!  Didn't the BSI/ISO committee
> propose doing just that a while ago?  I seem to remember reading some
> such proposal in Modus Quarterly.
> For ORD(-1) (that is, CARDINAL(-1)) that would mean an exception, since
> there is no CARDINAL value that corresponds to -1 (by definition).

Well, please note that the text of my recent message about ORD
and VAL was actually written last September.

Alan is correct about recalling BSI recommendations.   In a little
more detail, the BSI working group recommended to the ISO group:
(a) Kind of type change: "unsafe conversion" or "cast" or
                         "memory-preserving coercion" or
                         "subverts the type checking mechanism"
    Currently done by constructs like: "CARDINAL(i)"
    Proposal: use "CAST(CARDINAL,i)" having already done
              "FROM SYSTEM IMPORT CAST".
(b) Kind of type change: "safe conversion" or "coercion" or
                         "meaning-preserving coercion"
    Currently done by constructs like: "ORD('A')", "CHR(65)", ...
    Proposal: ORD, CHR, FLOAT, TRUNC and VAL would be moved to
              a module called Obsolete.   Instead use
              "CARDINAL('A')", "CHAR(65)", ...
Although proposal (a) has been accepted by the ISO Modula-2 working
group, proposal (b) was not accepted by the January 1988 ISO Modula-2
meeting.   (* However, recent correspondence on this news group from
Albert Meier suggests that at least one of the members who voted
against proposal (b) would now like to change his mind. *)

The position proposed at the January meeting (which has since been
incorporated into the BSI working group's documents) is to
keep proposal (a) but to replace proposal (b) by:
(c) Kind of type change: "safe conversion" or "coercion" or
                         "meaning-preserving coercion"
    Currently done by constructs like: "ORD('A')", "CHR(65)", ...
    Proposal: ORD, CHR, ... would remain as at present
              but VAL would be "deprecated".   Instead use
              "CONVERT(CARDINAL,'A')", "CONVERT(CHAR,65)", ...

Proposal (c) introduces a standard procedure called CONVERT
which is actually an enhanced version of VAL.   The name "VAL" was not
chosen because (i) the new function is an enhanced version of VAL
and (ii) the name VAL would be confusing because it is now being used
by some implementations for "unsafe" conversions.   The actual name
"CONVERT" wasn't liked by all members of the ISO/BSI working groups.
==
Barry Cornelius
==
Computer Science Group, School of Engineering and Applied Science,
University of Durham, Durham, DH1 3LE, England


              UUCP:        ...ukc!cs.nott.ac.uk!bjc

Tel: Durham (091 or +44 91) 374 2638, Secretary: 374 2630, Fax: 374 3740



Tue, 17 Nov 1992 16:46:00 GMT  
 from ORD to CARDINAL to CONVERT

|(a) Kind of type change: "unsafe conversion" or "cast" or
|                         "memory-preserving coercion" or
|                         "subverts the type checking mechanism"
|    Currently done by constructs like: "CARDINAL(i)"
|    Proposal: use "CAST(CARDINAL,i)" having already done
|              "FROM SYSTEM IMPORT CAST".
|(b) Kind of type change: "safe conversion" or "coercion" or
|                         "meaning-preserving coercion"
|    Currently done by constructs like: "ORD('A')", "CHR(65)", ...
|    Proposal: ORD, CHR, FLOAT, TRUNC and VAL would be moved to
|              a module called Obsolete.   Instead use
|              "CARDINAL('A')", "CHAR(65)", ...
|Although proposal (a) has been accepted by the ISO Modula-2 working
|group, proposal (b) was not accepted by the January 1988 ISO Modula-2
|meeting.   (* However, recent correspondence on this news group from
|Albert Meier suggests that at least one of the members who voted
|against proposal (b) would now like to change his mind. *)
|
|The position proposed at the January meeting (which has since been
|incorporated into the BSI working group's documents) is to
|keep proposal (a) but to replace proposal (b) by:
|(c) Kind of type change: "safe conversion" or "coercion" or
|                         "meaning-preserving coercion"
|    Currently done by constructs like: "ORD('A')", "CHR(65)", ...
|    Proposal: ORD, CHR, ... would remain as at present
|              but VAL would be "deprecated".   Instead use
|              "CONVERT(CARDINAL,'A')", "CONVERT(CHAR,65)", ...
|
|Proposal (c) introduces a standard procedure called CONVERT

Why introduce another standard procedure, when you can use the elegant
solution (b). I agree, that it is a good idea to introduce CAST, to force
the programmers who do unsafe conversion to have a FROM SYSTEM IMPORT...
line in their program. But I don't see the need for a CONVERT procedure.
IT happens often, that you have CARDINAL as well as INTEGER variables in
your program, and that you have to convert one type into the other.
So it's better to have a simple mean to do that ( CARDINAL(i) ) instead
of a more complicated one ( CONVERT(CARDINAL,i) ).

                                claudio



Thu, 17 Dec 1992 00:37:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Need to add to ord and convert to chr

2. #include "ord.ch"

3. Haskell: Why is Ord derived from Eq?

4. more about ORD and VAL

5. Ruby equivalent for ord() in Perl

6. Ord

7. Ord Function HELP Please HELP HELP HELP

8. newbie problem with 'ord' function

9. special function name for ord(c) ???

10. TCL equivalent of PHP's ORD() function

11. Tcl_GetInt and ord question

12. (in)compatibility between INTEGER and CARDINAL

 

 
Powered by phpBB® Forum Software