Thanks so much for your reply!
You're right of course, this is a silly loop - I'm trying to understand the semantics here which is what led me to the PL/I standard(s). The LRM says "previously saved" value and doesn't describe the type of the previously saved value, but I see it converting a BY expression (similar to TO) to arithmetic and not doing the same for TO. And, as you mention, it seems to be copying (when needed) the TO expression to a temporary.
But - let's consider this slightly different loop.... in the generated code it does copy the return value from the function call to VAL, and it does a fixed-len character comparison between IDX and this saved value (a CLC)... but the loop doesn't end anyway...
If I'm following things correct; at the end of the loop, the value of IDX would be converted to FIXED DEC, a 1 is added (since the BY value is an implied FIXED DEC 1) and that value would be converted back to CHAR(50) for storing to IDX. This value would then be compared with the previously saved value.
Since VAL returns a CHAR 50 that is also the conversion of a FIXED DEC value (either 10 or 5 - which is done to demonstrate that VAL is only invoked once), the first call to VAL would return a CHAR(50) that is the conversion of 10 to a CHAR(50). Evemtually, the value of IDX should be the same FIXED DEC 10 converted to CHAR(50).
Since both sides of the comparison are conversions of FIXED DEC to CHAR(50) - wouldn't this end the loop? Why is this one infinite?
test: proc options(main);
dcl flag fixed bin(31);
dcl idx char(50);
val: proc returns(char(50));
if(flag = 0) then return (10);
else do;
flag = 1;
return (5);
end;
end;
flag = 0;
do idx = 1 to val();
display('idx is ' || idx);
end;
end;
Perhaps these issues are why the standard converts the TO expression to an arithmetic value instead of leaving it as CHAR for the comparison? (Certainly saving an arithmetic value is a lot easier than a CHAR temporary.)
But - in either case - I don't think the loop should be infinite in this 2nd example... no?? (Maybe I'm missing something else?)
tdr