Re: out of memory, even tho remembered nothing!
- Posted by useless_ Oct 18, 2012
- 1741 views
But that's my point in that last post, testing for junk being a SEQUENCE doesn't work. EOF is defined as a CONSTANT, and those are defined as OBJECTs, ergo gets() does not return an ATOM.
I suspect that you have misunderstood the concept of OBJECT. The gets function returns an object. When that object contains a sequence, it's the read data and when that object contains an atom it signifies end-of-file. The CONSTANT called EOF is defined as an OBJECT with the ATOM value of -1. OBJECTs are containers that can contain either atoms or sequences.
The code you posted as not working will not work if 'junk' is defined as a sequence variable, but if defined as an object then it will work. The following should be working correctly ...
include std/console.e object junk junk = gets(readfile) while sequence(junk) do size += length(junk) display(size) --> simplier than ... puts(1,sprintf("%d",size)&"\r") junk = gets(readfile) end while
I had declared junk as an object in my code! I default to object a lot actually, just to avoid typecasting errors. It read past the end of file again.
useless

