Qu

close

Builtin index · File I/O

close(f)

Input: f · Output: no output

What it is

Flushes and releases a file handle. f (file handle, from fopen/StreamFile) is the handle to release.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
close(f)
f —not documented yet
no outputFlushes and releases a file handle.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

n = fopen("notes.txt", "w")
write_line(n, "line one")
write_line(n, "line two")
close(n)
print(read_all_text("notes.txt"))
# line one

# line two

output
line one
line two

from file-io

write("a", 1, "b")
print("")
f = fopen("scratch_write_demo.txt", "w")
write(f, "hello file")
close(f)
g = fopen("scratch_write_demo.txt", "r")
print(read_all(g))
close(g)
output
a 1 b
hello file

from repl-diagnostics

f = fopen("log.txt", "r")
for i = 0 to 1
    print(read_line(f))
end for
close(f)

g = fopen("log.txt", "r")
print(read_all(g))
close(g)
output
run started
value = 42
run started
value = 42

from file-io

ports = serial_ports()                              # e.g. ["COM3"], or [] with no hardware attached

conn = serial_open(ports[0], 9600, timeout_ms=500)
line = read_line(conn)                              # blocks up to 500ms; `none` if nothing arrived

if line != none
    print("got: {line}")
else
    print("no line arrived within the timeout")
end if
close(conn)
output
no line arrived within the timeout

from concurrency