content/blog/2022/04/fun-with-macros-do-file.markdown @ 578872d23f06 default tip
Links
| author | Steve Losh <steve@stevelosh.com> |
|---|---|
| date | Mon, 09 Sep 2024 10:31:31 -0400 |
| parents | ff107268c4e3 |
| children | (none) |
(:title "Fun with Macros: With-EOF-Handled" :snip "Part 4 in a series of short posts about fun Common Lisp Macros." :date "2024-06-23T13:45:00Z" :draft t) It's been a while (again), but it's time to take a look at another little Common Lisp macro that I find myself using fairly often: `with-eof-handled`. <div id="toc"></div> ## Usage Common Lisp has several functions for reading from character streams, e.g. `read-char` and `read-line`. The arguments for these functions follow a common pattern where they take `(&optional input-stream eof-error-p eof-value)` (and one more argument that's not relevant here). By default, calling one of these functions will signal an error if an end of file occurs. You can change this by passing true as the `eof-error-p` argument (which, despite its `-p` suffix should be a (generalized) boolean, *not* a predicate), in which case the `eof-value` will be returned instead of signaling an error. ```lisp ``` ## Implementation ## Result