James Giles wrote:
> Richard Maine wrote:
>
>>--On Friday, September 3, 2004 3:31 PM -0400 Jean Vezina
>><[log in to unmask]> wrote:
>>
>>
>>>What causes the problem is the string 5*abc
>>>
>>>Is it allowed to have a repeat count before
>>>an undelimited character string ?
>>
>>Yes. You can't have something like 5* as part of an
>>undelimited character string (that's item 4 in the list
>>of things you can't have). That restriction resolves
>>what would otherwise be a potential ambiguity.
>
>
> Since the 5* is not part of the undelimited string in this
> example, but is *intended* to be a repeat count, how does
> item 4 apply?
Because part (4) is the part that ensures that the 5*
is the repeat count, not part of the character constant.
Basically, there is no way to read in a character value
like 5*abc into a character string thing of length 5,
you need '5*abc'. The "5*" is always taken as a repeat count
if it is undelimited. (Or maybe I don't understand your
comment?)
>
>
>>F2003 even has specific mention of the case of a repeat
>>count followed by an undelimitted character string, which makes
>>the answer pretty unambiguous. That mention was to clear up
>>a more subtle point that came up in an interp. Hmm, probably
>>an f95 interp, so I suspect that same mention is in one of the
>>f95 corrigenda, even though I don't see it in the original f95...
>>Yep, there it is. It is in f95 corrigenda 2.
>
>
> For those of us with difficulty navigating the mysteries of the
> j3-fortran website, could you be more specific about the
> potential ambiguity? I don't see the mention in the F2003
> document (unless it was added after the FDC). Nor can
> I think of an ambiguous case. (I suppose with 20 minutes of
> spare time I could track down f95 corrigenda 2, and hope
> it's written in normal English.)
>
The ambiguity is with trying to read things with different
types when there is a repeat count. The interesting cases
are things like reading 2*(1.0, 0.0). Is it 2 complex
values or 3 character values? (The answer is, "Yes, either
is fine, depending on the read variables"). It's not
one complex and 2 characters, for example.
I put the interp below. As you can see, it's written in
normal English ;) .
Dick Hendrickson
> --
> J. Giles
>
> "I conclude that there are two ways of constructing a software
> design: One way is to make it so simple that there are obviously
> no deficiencies and the other way is to make it so complicated
> that there are no obvious deficiencies." -- C. A. R. Hoare
>
The full interp is here.
NUMBER: 000025
TITLE: List-directed input: types of variables corresponding to
repeated values
KEYWORDS: List-directed input, repeated values
DEFECT TYPE: Erratum
STATUS: Included in corrigendum/complete
QUESTION:
When a repeat count is used in list-directed input, must all the
variables into which the repeated value is read have the
same type?
I see no reason in the standard to assume that restriction,
but at
least one Fortran 90 implementation assumes it.
ANSWER:
No, the variables are not required to be of the same type,
but the
type of the repeated constant is either a literal constant, or a
nondelimited character constant, but not both (10.8, "where
<c> is a
literal constant or a nondelimited character constant").
Whether
certain forms of a repeated constant are treated as a literal
constant or a nondelimited character constant is determined
by the
type of the first variable which consumes this value.
Indeed, how
many characters from the input record are part of <c> is
dependent on
the type of the first variable which consumes a value from that
<r*c>.
For example, the input
2*(1.0, 0.0)
conforms to the standard when consumed by three list items
of type
character or by two list items of type complex. If there
are three
character variables, the first two get the value "(1.0",
while the
third gets the value "0.0)". If there are two complex
variables,
they both are assigned the value (1.0,0.0).
Similarly, the input
2*.TRUE.
can be consumed by two logical variables, or two character
variables,
but not by one character and one logical variable.
An edit is provided to clarify the situation.
EDITS:
In section 10.8.1, add the following as a new paragraph,
just before
Note 10.26 [175:33+].
"For the <r*c> form of an input value, the constant <c> is
interpreted as a nondelimited character constant if the
first list
item corresponding to this value is of type default
character,
there is a nonblank character immediately after <r*>,
and that
character is not an apostrophe or a quotation mark;
otherwise, <c>
is interpreted as a literal constant."
SUBMITTED BY: Robert Corbett
HISTORY: 98-155 m145 Submitted (part 3)
WG5/N1410 Draft answer
01-159r1 m156 Passed unanimously by J3 meeting
01-224r1 m157 Passed by J3 letter ballot
WG5/N1435 Passed by WG5 ballot
|