J3/12-115 To: J3 From: Malcolm Cohen Subject: Editorial changes for intrinsic procedures. Date: 2012 January 30 1. Introduction There are a number of minor wording problems with several of the intrinsic procedures, mostly in the Resolve Value paragraphs. This paper describes some of these problems and proposes fixes. 2. Problems with INDEX The problems noticed are listed below. These problems are not limited to INDEX, but INDEX has a great number of them. (a) "I" is introduced with no explanation or definition; the standard should not be using IMPLICIT INTEGER(I-N) internally! There is a fix for this in 12-112. (b) There is no accounting for KIND, so we talk about LEN(SUBSTRING) and LEN(STRING) and this is problematic if the lengths are larger than can be represented by default integer. The correct fix is to use text, e.g. "length of STRING", where possible. Where this is not possible, we should use LEN(STRING,KIND). We already do this for CMPLX, unnecessarily at [337:26] but not unnecessarily at [337:27-28] (though CMPLX also has problems). Or we could use LEN(STRING[,KIND]), like we do for MAXLOC with MASK. In any case we should be consistent about it. (c) Sometimes we say "the result is", other times we say "is returned". Since the paragraph is Result Value not Function Reference we should refer to the value of the result, not say anything like "is returned". (d) It is not an error, but when SUBSTRING=='' the result value is overspecified in Case (i); the first sentence says that it will have the value 1 (viz the minimum integer I such that 'abc'(I:I-1)==''), and the second sentence says that "one is returned". (e) Similarly for SUBSTRING=='' and BACK=.TRUE.; the first sentence says that the value is LEN(STRING)+1 and the second sentence says that the value is LEN(STRING)+1. (f) Maybe not an error if one reads the text leniently, but for INDEX('ab','abc') we first ask whether there is an integer I such that STRING(I:I+2)==SUBSTRING, and this is out of bounds for all integer I and thus meaningless. This could be fixed by reversing the order of the sentences. (g) The second sentence of Case (i) and Case (ii) are not conditionalised on the status of BACK=. It is rather unsatisfactory to have to deduce that they should be based on the contradiction that would result if they were not. Edits will follow in the r1 of this paper. 3. CMPLX problem The Result Value paragraph for CMPLX does not specify the value of CMPLX(X,Y) - it requires the KIND argument to be present. [337:26] 13.7.36 CMPLX, Result Value paragraph, second sentence, Delete ", KIND". {This is completely unnecessary and only works if KIND is present.} [337:28] Append new sentence to paragraph "The result of CMPLX(X,Y) is equal to CMPLX(X,Y,KIND(0.0)).". {Specify what the result of CMPLX(X,Y) is.} 4. COUNT problem The Result Value paragraph for COUNT does not specify the value of COUNT(..., KIND), Case (i) only specifies the result of COUNT(MASK) and Case (ii) only specifies the result of COUNT(MASK,DIM). [339:4] 13.7.41 COUNT, Result Value paragraph, Change "The result of COUNT(MASK)" to "If DIM is absent or MASK has rank one, the result". {Specify both COUNT(MASK) and COUNT(MASK,KIND=...), and catch the redundant DIM case as well.} [339:6] Delete "If MASK ... COUNT (MASK).". {Now handled by Case (i).} [339:7-8] Change "Otherwise" to "If DIM is present and MASK has rank n>1", Change "of COUNT(MASK,DIM)" to "of the result", Change "COUNT (MASK ($s_1$, ..., $s_n$))" to "the number of true elements of MASK ($s_1$, ..., $s_n$)". NOTE: Thus making that sentence read "If DIM is present and MASK has rank $n > 1$, element ( $s_1$, $s_2$, ..., $s_{\text{DIM}-1}, $s_{\text{DIM}+1}$, ..., $s_n$) of the result has a value equal to the number of true elements of MASK( $s_1$, $s_2$, ..., $s_{\text{DIM}-1}, :, $s_{\text{DIM}+1}$, ..., $s_n$)." {Correctly specify COUNT(MASK,DIM) and COUNT(MASK,DIM,KIND). Note that the corrected version is not significantly longer than the incorrect version!} 5. FINDLOC problem The Result Value paragraph for FINDLOC does not specify the value when KIND is present. The specification of the result is contradictory - the first sentence says "The result ... is [an] array whose element values are the values of the subscripts of an element of ARRAY whose value matches VALUE." without regard as to whether such an element even exists. This needs to be completely rewritten. Edits will follow in the r1 of this paper. 6. IACHAR problem The Result Value sentence suddenly changes halfway from talking about the result in all cases to the result only in the KIND-absent case. [352:16-17] Change "and satisfies the inequalities ... 127)" to "; it is non-negative and less than or equal to 127". Perhaps we should consider requiring KIND to specify an integer kind capable of representing 127? 7. ICHAR problem This is similar to IACHAR. There is an additional problem in that ICHAR(ucs4char,1) is highly likely not to work (it is a great pity that we added the unnecessary KIND argument to this intrinsic!). [355:11] 13.7.77, Result Value paragraph, Change "and is in the range ... $n - 1$" to "; it is non-negative and less than $n$". OPTIONAL EDIT: [355:9] Append "The kind type parameter shall specify an integer type capable of representing $n$, where $n$ is the number of characters in the collating sequence." And delete ", where ... sequence" from [355:11-12]. 8. INT problem The Result Value paragraph does not specify the result when KIND is present. Also, Case (ii) does not work when |A| is greater than HUGE(0). One might conjecture that by "integer" we meant "representable integer in the kind of the result", as this is the "friendliest" answer, but I do not think so so the edits below assume that when we wrote "integer" we meant the mathematical "integer" as we usually do. (In the context of the INT intrinsic it is definitely unclear as to which should be meant so ought to be clarified; if there is any disagreement we will have to have an interp...). [357:1-5] 13.7.81 INT, Result Value paragraph, Replace Cases (i) to (iii) with "Case (i) : If A is of type integer, its value shall be representable in the kind of the result and the result has that value. Case (ii) : If A is of type real, there are two cases: if |A|<1, the result has the value zero; otherwise the largest integer that is less than or equal to |A| shall be representable in the kind of the result and the result has that value. Case (iii) : If A is of type complex, the result has the same value as for REAL(A)." 9. LBOUND problem a. The result value is unspecified when KIND is present. b. Case (i) says that for an array section, "the result value is 1", without limiting itself to the case when DIM is present. [360:11] 13.7.90 LBOUND, Result Value paragraph, Change "LBOUND (ARRAY, DIM)" to "and DIM is present, the result" {Handle KIND automatically.} [360:12] After "Otherwise" insert ", if DIM is present,". {Fix contradiction.} [360:14] Append sentence "The value of LBOUND(ARRAY,KIND=KIND) is exactly analogous to LBOUND(ARRAY)." {This is not a good solution, but is better than nothing. Perhaps the r1 of this paper will have a better edit?} 10. LCOBOUND problem This is similar to LBOUND, but because we don't have cosections it is easy to repair this. [360:31] 13.7.91 LCOBOUND, Result Value paragraph, Change "LCOBOUND (COARRAY, DIM)" to "If DIM is present, the result". [360:33] Replace "LCOBOUND (COARRAY)" with "If DIM is absent", [360:34] Replace "LCOBOUND (COARRAY, $i$)" with "the lower cobound for cosubscript $i$ of COARRAY". 11. MAXLOC problem The Result Value paragraph for MAXLOC does not specify the value when KIND is present. Nor when BACK is present - read cases (i) to (iii) carefully, they ALL exclude BACK! Arguably case (iii) contradicts cases (i) and (ii) with its unconditional "Otherwise". Still, it's easier to fix than FINDLOC. [367:1] "The result of MAXLOC (ARRAY)" ->"If DIM does not appear and MASK is absent, the result" {Include KIND and BACK.} [367:5] "The result of MAXLOC (ARRAY, MASK = MASK)" ->"If DIM does not appear and MASK is present, the result". {Include KIND and BACK.} [367:10-11] ", MAXLOC (ARRAY, DIM = DIM [, MASK = MASK]) is a scalar whose value is" ->"and DIM is specified, the result has a value equal to" {Include KIND and BACK.} [367:11,14] Before "]" insert ", KIND = KIND, BACK = BACK". {Include KIND and BACK, twice.} [367:11] After "Otherwise," insert "if DIM is specified,". {Conditionalise the rest on DIM being present.} 12. MINLOC Same as MAXLOC, mutatis mutandis. 13. UBOUND Same as LBOUND, mutatis mutandis. 14. UCOBOUND Same as LCOBOUND, mutatis mutandis. ===END===