-
-
Save squadette/cda3c1e40d2c3c7cdcf3d7e9c3da015b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# given file path, print number of lines or report I/O errors from opening/reading | |
with file_contents(filename) do | |
case error_free (contents): | |
print number_of_lines(contents) | |
case io_error(errno): | |
print "I/O error opening file: #{perror(errno)}" | |
end | |
end | |
def file_contents(filename) : { error_free: contents, io_error: errno } | |
with syscall_open(filename) do | |
case error_free (fd): | |
with syscall_read(fd) do | |
case error_free(contents): | |
yield error_free<contents> | |
case io_error(errno): | |
yield io_error<errno> | |
end | |
end | |
case io_error (errno): | |
yield io_error<errno> | |
end | |
end | |
def syscall_open(filename) : { error_free: fd, io_error: errno } | |
# ...FFI... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment