with-open-file example
More complex example. There is a built-in lisp macro of the same name that does almost exactly this.
(defmacro with-open-file ((var &rest args) &body body)
`(let ((,var (open ,@args))) ; open file
(progn ,@body) ; execute body
(when (streamp ,var) (close ,var)))) ; close
unwind-protect is talked about later on, but it ensures the file is closed even if an error occurs