mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2025-12-06 02:40:26 -08:00
Always close stream in with-input-from-string & Cosmetic changes
The Common Lisp Standard defines that with-input-from-string always closes the input stream that it creates. But with the current definition it would only be closed in the case of an index variable being provided. This change wraps the code for both cases (index given or not) in a unified unwind-protect form, updates the index if present, and always closes the stream. It also unifies the processing of declarations. Downcase code & fix indentation: Set the uppercased code in lower case to harmonise appearance and increase readability. Differentiated indentation for the first forms in unwind-protect and multiple-value-prog1 helps to understand their special meaning.
This commit is contained in:
parent
1d7551c773
commit
72560efa5a
1 changed files with 11 additions and 12 deletions
|
|
@ -34,18 +34,17 @@ automatically closed on exit."
|
|||
Evaluates FORMs with VAR bound to a string input stream from the string that
|
||||
is the value of STRING-FORM. The stream is automatically closed on exit.
|
||||
Possible keywords are :INDEX, :START, and :END."
|
||||
(if index
|
||||
(multiple-value-bind (ds b)
|
||||
(find-declarations body)
|
||||
`(LET ((,var (MAKE-STRING-INPUT-STREAM ,string ,start ,end)))
|
||||
,@ds
|
||||
(UNWIND-PROTECT
|
||||
(MULTIPLE-VALUE-PROG1
|
||||
(PROGN ,@b)
|
||||
(SETF ,index (FILE-POSITION ,var)))
|
||||
(CLOSE ,var))))
|
||||
`(LET ((,var (MAKE-STRING-INPUT-STREAM ,string ,start ,end)))
|
||||
,@body)))
|
||||
(multiple-value-bind (ds b)
|
||||
(find-declarations body)
|
||||
`(let ((,var (make-string-input-stream ,string ,start ,end)))
|
||||
,@ds
|
||||
(unwind-protect
|
||||
,(if index
|
||||
`(multiple-value-prog1
|
||||
(progn ,@b)
|
||||
(setf ,index (file-position ,var)))
|
||||
`(progn ,@b))
|
||||
(close ,var)))))
|
||||
|
||||
(defmacro with-output-to-string ((var &optional string &rest r &key element-type) &rest body)
|
||||
"Syntax: (with-output-to-string (var [string-form]) {decl}* {form}*)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue