Barry_Cornelius@durham.ac.UK.UUCP (06/30/88)
Alan Lovejoy <pdn!alan@NET.UU.UUNET> writes (28Jun at 04:48:57 GMT): > 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 JANET: Barry_Cornelius@uk.ac.dur.mts Internet: Barry_Cornelius%mts.dur.ac.uk@cunyvm.cuny.edu UUCP: ...ukc!cs.nott.ac.uk!bjc BITNET/EARN: Barry_Cornelius%DUR.MTS@AC.UK Tel: Durham (091 or +44 91) 374 2638, Secretary: 374 2630, Fax: 374 3740
claudio@forty2.UUCP (Claudio Nieder) (07/05/88)
In article <INFO-M2%88063018035481@UCF1VM| Info-Modula2 Distribution List <INFO-M2%UCF1VM.bitnet@jade.berkeley.edu> writes: |(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