Re: out of memory, even tho remembered nothing!
- Posted by mattlewis (admin) Oct 18, 2012
- 1549 views
Well, anyhow, this fails to run properly also:
junk = gets(readfile) while sequence(junk) do size += length(junk) puts(1,sprintf("%d",size)&"\r") junk = gets(readfile) end while
This can be shortened slightly using a feature introduced in 4.0:
while sequence(junk) with entry do size += length(junk) puts(1,sprintf("%d",size)&"\r") entry junk = gets(readfile) end while
Execution of the loop always starts at entry, skipping the condition the first time through.
And so i am still tripping over typecasting. To me, -1 is not a sequence, nor should it be TRUE. To avoid the horrors like this, the following convoluted while must be used:
junk = gets(readfile) while not equal(-1,junk) do size += length(junk) puts(1,sprintf("%d",size)&"\r") junk = gets(readfile) end while
Yes, I typically check for a sequence, since you only get an atom returned from gets() after you've read all of the file.
If it's voteable, i vote for replacing "while not equal(-1,junk) do" with "while junk do".
Anyhoo, this is getting off my original point, and i am glad Matt is fixing the memory leak in gets().
Yeah, this is related to the long debated equals() vs = reform. But I don't see changing the truth value of atoms changing (the sequence as a boolean / truth value is more likely).
Matt