Skip to content

Instantly share code, notes, and snippets.

@Colelyman
Last active October 23, 2018 03:39
Show Gist options
  • Save Colelyman/1521aac0e2801be554b9817d9e4346d9 to your computer and use it in GitHub Desktop.
Save Colelyman/1521aac0e2801be554b9817d9e4346d9 to your computer and use it in GitHub Desktop.
A Common Lisp macro that opens a file and closes it after some computation is done.
(defmacro open-file-defer-close (file-path file-handle &body body)
"Opens FILE-PATH as FILE-HANDLE, executes BODY and finally closes FILE-HANDLE."
`(let ((,file-handle ,(open file-path)))
,@body
(close ,file-handle)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment