A convenience macro for working on an open file.
Opens a file named name, giving the variable stream to body to perform the stream operations. It then closes the file when body finishes. Only the stream variable is visible to body. Body sees neither name nor parameters.
let line = "";
let dylan-experience = #f;
with-open-file(file = "resume.txt")
while(line & ~ dylan-experience)
dylan-experience := regexp-position(line, "dylan");
line := read-line(file, on-end-of-stream: #f);
end while;
end;
format-out(if(dylan-experience)
"Hire this person now!\n"
else
"Try someone else\n"
end if);
with-open-file ( (stream) = (locator), (keys) )
(body)
end
| stream | A variable name. This will be bound to an instance of <file-stream>. |
| name | An instance of <file-locator> or <string>. |
| parameters | Make keywords used when creating stream. |
| body | A series of semicolon-separated expressions. |