-
Notifications
You must be signed in to change notification settings - Fork 2
IO Concepting
Caleb Callaway edited this page Aug 12, 2017
·
1 revision
- requires builtin or standard error type, and error list type
- Builtin types:
- part of environment bringup?
- standard newt files
- no code generation/preprocessing
- validate similarily to for/if/while loops
- can't return anything from a using block except an error--is this a problem?
- premature termination--file contents not what we want?
- allow inferred return types?
- I/O classes must be defensively designed to handle escaping references to closed files/de-allocated resources
- resource requires statefulness, i.e objects?
- function that returns stream state object?
using := (resource:__, handler:(__) -> errors) -> errors {
errors = resource.setup()
if (errors == @errors) {
handler_errors := handler(resource)
return handler_errors.concatenate(resource.teardown())
}
return errors
}
res := using file_handle('tmp.txt', 'rb') as input_file -> {
for line in input_file.read_line() {
print(line)
}
subject = input_file.read_line()
while(subject != nil) {
print(subject.value)
subject = subject.next
}
}