3 ms·
Of course, other flow control options are available which also prevent this mess - e.g: int failed = with_file("foo", |file|{ write(file, "bar"); })
by richardwhiuk 4y ago
Of course, other flow control options are available which also prevent this mess - e.g:
int failed = with_file("foo", |file|{
write(file, "bar");
});
fn with_file(char* foo, lambda: Fn(File)){
let f = open(foo);
if !f { return f; }
let err = lamda(f);
let cerr = close(f);
if !err {
return err;
}
return cerr;
}
- metadat 4y agoIs this Rust or a different language?
- varajelle 4y agoLooks like a mix of Rust and C. Like a French person trying to speak English, but still saying half of the words in French.
- richardwhiuk 4y agoI was aiming for pseudo-code. You can write it in C, but it's a little less readable due to the lack of first class lamdas.