f



WHILE (67)

Just encountered an interesting "feature" when I tried to run my REXX script
with Reginald REXX.   It doesn't like the line:

WHILE (Lines("test.dat")) DO
END

because it doesn't think that any number other then 1 is "TRUE"... :-)




0
REXX
11/21/2003 10:04:31 PM
comp.lang.rexx 2135 articles. 0 followers. Post Follow

11 Replies
8812 Views

Similar Articles

[PageSpeed] 38

On Fri, 21 Nov 2003 22:04:31 GMT, REXX Guy <rexxguy@yahoo.com> wrote:

>  it doesn't think that any number other then 1 is "TRUE"... :-)

I thought Lines() always returned either 1 (if there are lines left to
read) or 0 (if there are none left to read). That's the way it works
here on OS/2 Classic Rexx, anyway.

-- 
Michael DeBusk, Co-Conspirator to Make the World a Better Place
Did he update http://home.earthlink.net/~debu4335/ yet?
0
Michael
11/22/2003 6:02:39 AM
>>  it doesn't think that any number other then 1 is "TRUE"... :-)

Very deliberate.  Boolean values are 0 or 1.  This saves you from a lot of
ambiguity that (say) C has, and avoides the need for a 'Boolean' datatype.

> I thought Lines() always returned either 1 (if there are lines left to
> read) or 0 (if there are none left to read). That's the way it works
> here on OS/2 Classic Rexx, anyway.

OS/2 and later only (and a sore point).  Lines was originally intended to
return the number of lines in a file, however much that cost.   It got
diluted, so now there continues to be confusion about it, 15 years on ....

Mike Cowlishaw


0
Mike
11/22/2003 2:22:11 PM
In comp.lang.rexx REXX Guy wrote:

> Just encountered an interesting "feature" when I tried to run my
> REXX script with Reginald REXX.   It doesn't like the line:
> 
> WHILE (Lines("test.dat")) DO
> END
> 
> because it doesn't think that any number other then 1 is "TRUE"...
> :-) 

Regina includes
"As with all the functions operating on streams, you can safely 
assume very little about this function, so consult the system and 
implementation specific documentation."

"The ANSI Standard has extended this function from TRL2. It allows an 
option:
 [C]
 (Count) Returns the actual number of complete lines remaining in the 
stream, irrespective of how expensive this operation is."

And the default behavior is to return (boolean)  0 or 1

  DO WHILE LINES() > 0
    PULL lin
    Say lin
  END

0
Mark
11/22/2003 4:01:15 PM
On Sat, 22 Nov 2003 14:22:11 -0000, Mike Cowlishaw
<mfcowli@attglobal.net> wrote: 

>  Lines was originally intended to return the number of lines in a
>  file, however much that cost.

It makes sense that it would do so. Several times I've wanted a
function which would do just that.

-- 
Michael DeBusk, Co-Conspirator to Make the World a Better Place
Did he update http://home.earthlink.net/~debu4335/ yet?
0
Michael
11/22/2003 6:29:40 PM
In <PZvvb.14769$Zy5.3835@newssvr29.news.prodigy.com>, on 11/21/2003
   at 10:04 PM, "REXX Guy" <rexxguy@yahoo.com> said:

>Just encountered an interesting "feature" when I tried to run my REXX
>script with Reginald REXX.   It doesn't like the line:

>WHILE (Lines("test.dat")) DO

Correct. The reult of lines can be greater than 1, in which case the
while will fail. Change the While to a comparison.

-- 
     Shmuel (Seymour J.) Metz, SysProg and JOAT

Unsolicited bulk E-mail will be subject to legal action.  I reserve
the right to publicly post or ridicule any abusive E-mail.

Reply to domain Patriot dot net user shmuel+news to contact me.  Do
not reply to spamtrap@library.lspace.org

0
Shmuel
11/23/2003 1:16:15 AM
In <3_Cvb.13051$Rk5.4534@newsread1.news.atl.earthlink.net>, on
11/22/2003
   at 06:02 AM, Michael DeBusk <m_debusk@despammed.com> said:

>I thought Lines() always returned either 1 (if there are lines left
>to read) or 0 (if there are none left to read).

No. I don't recall whether the behavior of Lines on OS/2 SAA REXX is a
standard-compliant deviation, but ANSI definitely defines lines as
returning the number of lines remaining.

-- 
     Shmuel (Seymour J.) Metz, SysProg and JOAT

Unsolicited bulk E-mail will be subject to legal action.  I reserve
the right to publicly post or ridicule any abusive E-mail.

Reply to domain Patriot dot net user shmuel+news to contact me.  Do
not reply to spamtrap@library.lspace.org

0
Shmuel
11/23/2003 1:17:57 AM
 >> I thought Lines() always returned either 1 (if there are lines left
 >> to read) or 0 (if there are none left to read).

 > No. I don't recall whether the behavior of Lines on OS/2 SAA REXX is a
 > standard-compliant deviation, but ANSI definitely defines lines as
 > returning the number of lines remaining.
 
If there's no interpreter following ANSI here, then your "no" is wrong,
because Lines() always returns 0 or 1 then. IRL. The one and only valid
answer or solution, both in ANSI as RL, is always:

          DO WHILE Lines(file)>0    (or anything that's equal to !=0)

OS/2 REXX returns 0 or 1, and AFAIK one cannot add a Lines() function
which always successfully returns the number of remaining lines. Such
an overriding Lines()-function would slow down file-I/O too anyway,
because you actually have to read all remaining lines and return to
where you came from each time (unless your Lines() return 0).



---
0
tight
11/23/2003 3:12:03 AM
In article <DWCw/Akcu1TM090yn@f.it>, tight@f.it says...
> 
>  >> I thought Lines() always returned either 1 (if there are lines left
>  >> to read) or 0 (if there are none left to read).
> 
>  > No. I don't recall whether the behavior of Lines on OS/2 SAA REXX is a
>  > standard-compliant deviation, but ANSI definitely defines lines as
>  > returning the number of lines remaining.
>  
> If there's no interpreter following ANSI here, then your "no" is wrong,
> because Lines() always returns 0 or 1 then. IRL. The one and only valid
> answer or solution, both in ANSI as RL, is always:
> 
>           DO WHILE Lines(file)>0    (or anything that's equal to !=0)
> 

Don't use != 0. It could go wrong when -1 is returned because of some 
other failure. I've run into this :)
0
Gert
11/23/2003 3:36:24 PM
In <DWCw/Akcu1TM090yn@f.it>, on 11/23/2003
   at 04:12 AM, tight@f.it (Jean) said:

>If there's no interpreter following ANSI here, 

If your grandmother had wheels she'd be a wagon. he original article
described a pronlem caused by the interpreter following ANSI when the
code wasn't written for it.

>then your "no" is wrong,

But since the OP was using an interpreter that *DID* follow ANSI, my
"no" was correct.

>because Lines() always returns 0 or 1 then. 

No. Just ask the OP.

>Such an overriding Lines()-function would slow down file-I/O too anyway,

Of course; that's why OREXX violates ANSI. But what the OP is seeing
is correct behavior per ANSI, abd also per Mike. I don't see how the
answer could be more definitive.

-- 
     Shmuel (Seymour J.) Metz, SysProg and JOAT

Unsolicited bulk E-mail will be subject to legal action.  I reserve
the right to publicly post or ridicule any abusive E-mail.

Reply to domain Patriot dot net user shmuel+news to contact me.  Do
not reply to spamtrap@library.lspace.org

0
Shmuel
11/23/2003 4:31:33 PM
this one works:

CheckPaidAddr = 'test.dat'

rc = STREAM(CheckPaidAddr, 'C', 'OPEN READ');

DO WHILE LINES(CheckPaidAddr)

END;

Steinar


"REXX Guy" <rexxguy@yahoo.com> wrote in message
news:PZvvb.14769$Zy5.3835@newssvr29.news.prodigy.com...
> Just encountered an interesting "feature" when I tried to run my REXX
script
> with Reginald REXX.   It doesn't like the line:
>
> WHILE (Lines("test.dat")) DO
> END
>
> because it doesn't think that any number other then 1 is "TRUE"... :-)
>
>
>
>


0
Steinar
11/23/2003 6:10:33 PM
In article <3fc00ac5$3$fuzhry+tra$mr2ice@news.patriot.net>,
Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid> wrote:
% In <3_Cvb.13051$Rk5.4534@newsread1.news.atl.earthlink.net>, on
% 11/22/2003
%    at 06:02 AM, Michael DeBusk <m_debusk@despammed.com> said:
% 
% >I thought Lines() always returned either 1 (if there are lines left
% >to read) or 0 (if there are none left to read).
% 
% No. I don't recall whether the behavior of Lines on OS/2 SAA REXX is a
% standard-compliant deviation, but ANSI definitely defines lines as
% returning the number of lines remaining.

The text description gives that impression, but the formal description
makes it optional. The text description of CHARS is better.

  9.7.3   CHARS
  CHARS indicates whether there are characters remaining in the named
  stream.  Optionally, it returns a count of the characters remaining and
  immediately available.

  [error checking]

  call Config_Stream_Count Stream, 'CHARS', Option
  return #Outcome


  [...]

  9.7.6   LINES
  LINES returns the number of lines remaining in the named stream.

  [error checking]

  Call Config_Stream_Count Stream, 'LINES', Option
  return #Outcome

The formal description is the description of Config_Stream_Count, which
says

  5.8.10     Config_Stream_Count

  [...]

  If the option is 'N' and #Outcome is set non-zero, #Outcome shall be
  1, or be the number of characters (or the number of lines if Operation
  is 'LINES') which could be read from the stream before resetting.

  [...]

  If the option is 'C' and #Outcome is set non-zero, #Outcome shall be the
  number of characters (or the number of lines if the Operation is
  'LINES') which can be read from the stream without delay and before
  resetting .

which makes no distinction between `chars' or `lines' wrt #Outcome being
1 or the true count. 
-- 

Patrick TJ McPhee
East York  Canada
ptjm@interlog.com
0
ptjm
11/24/2003 12:03:41 AM
Reply: