Re: true/false atoms?
- Posted by Kat <KSMiTH at PELL.NET> Aug 12, 1999
- 528 views
----- Original Message ----- From: Pete Eberlein <xseal at HARBORSIDE.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Thursday, August 12, 1999 1:50 AM Subject: Re: true/false atoms? > > >while datafound = "false" or data != -1 do > > > > The '=' operator can't be used here. Try instead: > > > > while equal( datafound, "false" ) or data != -1 do > > While this solves the first "Error: true/false condition must be an atom", > the second test "data != -1" will cause the same error. You must declare > data as an "object" because the gets function will return -1 when it > reaches end-of-file. "But that's I'm testing for!!!" you say, but > remember all the while data will be a sequence of text read from the > file... for instance say data holds {1,1,2,3,5,8}. The result of "data != > -1" will be "{1,1,2,3,5,8} != -1" whose result is the same as "{1 != -1, 1 > != -1, 2 != -1, 3 != -1, 5 != -1, 8 != -1}" or "{1,1,1,1,1,1}". When an > sequence is applied to an atom using an arithmetic operator, the atom is > applied to each element of the sequence. So the result is still a > sequence and the "true/false condition must be an atom" error will be > reported. > > The solution: declare data as an object and use the sequence() function to > test data to make sure it is a sequence. > > while equal( datafound, "false" ) or sequence( data ) do > > Since the only time gets() returns an atom is when it returns -1, it is > safe to use the sequence() test to check for end-of-file. The newer code, with David's and Pete's code: while equal( datafound, "false" ) or sequence( data ) do data = gets(dctstrfile) if ( find(datatofind,data) != 0 ) then datafound = "true" end if end while It still faults at the find() when data is set to -1 ( which i must say, happens extremely fast compared to the pascal compiled code! ) , so i must set yet another if test.... while equal( datafound, "false" ) or sequence( data ) do data = gets(dctstrfile) if sequence(data) and ( find(datatofind,data) != 0 ) then datafound = "true" end if end while Now it misses the end of file, and keeps on running, doing nothing..... no errors, nothing, it never leaves the while loop. I put a printf, gets , and abort after the while, to see if it was leaving the while loop,, and the printf never is hit,, so i told it to print out the file in the while loop, it got to the end of the file and printed blank lines. I had opened the file as "rb" (i have non-char tokens in it) , and changed it to "r", to no effect. Any ideas? Please? Kat