Re: Two possible bugs in docs! <-- Not quite...
- Posted by Robert B Pilkington <bpilkington at JUNO.COM> Jun 19, 1998
- 677 views
On Fri, 19 Jun 1998 08:54:32 -0400 Alan Tu <ATU5713 at COMPUSERVE.COM> writes: >1. This is an example program under the <seek> library routine in >library.doc > > include file.e > > integer fn > fn =3D open("mydata", "r") > -- read and display first line of file 3 times: > for i =3D 1 to 3 do > puts(1, gets(fn)) = > > if seek(fn, 0) then > puts(1, "rewind failed!\n") > end if > end for > >Or is this so that the loop will be performed three times? i is not >mentioned anywhere within the for loop. The comment says that it will read and display the first line of the file 3 times. The loop variable (i, in this example) doesn't have to be mentioned inside the loop. It's just what happens most of the time. >2. I've noticed this for a while. This is the <atom> routine (but if >this is a bug, sequence and integer have the same bug). > > line =3D gets(0) > if atom(line) then > puts(SCREEN, "end of file\n") > end if > >As I understand it, atom returns a 0 or 1. So >if atom(line) then >doesn't make sense. A boolean expression returns 0 for false, or non-zero for true: object line line = 5 if atom(line) then -- atom(line) = 1 puts(1, "EOF\n") end if if 5 then -- Nonzero means TRUE, so the following line is executed puts(1, "5 is not false (0)\n") end if if 0 then -- zero = false, so the following line isn't executed puts(1, "Hey! I'm not supposed to be here!\n") end if line = "What??" if length(line) then -- length(line) = 6, nonzero, so true printf(1, "The line has a length of %d\n", {length(line)}) end if _____________________________________________________________________ You don't need to buy Internet access to use free Internet e-mail. Get completely free e-mail from Juno at http://www.juno.com Or call Juno at (800) 654-JUNO [654-5866]