eof
result = eof(f)
Input: f · Output: result
What it is
Checks whether f (file handle, opened readable) has any bytes left to read from the current position.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = eof(f) | f booleannot documented yet | result boolean | Returns a boolean: true iff none remain. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
f = fopen("streaming_demo.txt", "w")
for i = 0 to 4
write_line(f, "line " + str(i))
end for
close(f)
g = fopen("streaming_demo.txt", "r")
n = 0
while not eof(g)
line = read_line(g)
n = n + 1
end while
close(g)
print("lines read = {n}")
from tour
n = fopen("notes.txt", "w")
write_line(n, "line one")
write_line(n, "line two")
close(n)
function drain(s)
total = ""
while not eof(s)
total = total + read_line(s) + "|"
end while
close(s)
return total
end function
a = drain(StreamFile("notes.txt"))
print(a) # line one|line two|
b = drain(StreamURL("https://example.com/"))
print(length(b) > 0) # true -- some HTML came back
line one|line two| true
from file-io
function drain(s)
total = ""
while not eof(s)
total = total + read_line(s) + "|"
end while
close(s)
return total
end function
# Written here so the file half runs; the URL half cannot be, since a
# documentation build must not depend on the network being up or on a
# third party's page not changing under it.
w = fopen("stream_notes.txt", "w")
write_line(w, "one")
write_line(w, "two")
close(w)
a = drain(StreamFile("stream_notes.txt"))
b = drain(StreamURL("https://example.com/"))
print("a = {a}")
print("b length = {length(b)}")
from tour
How it works
§ file/directory I/O extensions + type casts (2026-08-26, keep this already-large match's diff footprint small while another pass concurrently edits this same file. See fs_ops::call's own doc comment for what each name does. eof(f) on a Value::UrlStream (from StreamURL) — see net_ops::stream_eof's own doc comment. Pulled out of the combined fs_ops arm just below (which only knows about Value::File) so eof dispatches across both stream kinds, the same "same method name, same behavior" polymorphism read_line/read_all/close above already give.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.