User Tools

====== Macro WITH-OPEN-STREAM ====== ====Syntax==== * **with-open-stream** (//var// //stream//) //declaration//''*'' //form//''*'' → //result//''*'' ====Arguments and Values==== * //var// - a //[[CL:Glossary:variable]]// //[[CL:Glossary:name]]//. * //stream// - a //[[CL:Glossary:form]]//; evaluated to produce a //[[CL:Glossary:stream]]//. * //declaration// - a **[[CL:Symbols:declare]]** //[[CL:Glossary:expression]]//; not evaluated. * //forms// - an //[[CL:Glossary:implicit progn]]//. * //results// - the //[[CL:Glossary:values]]// returned by the //forms//. ====Description==== **with-open-stream** performs a series of operations on //stream//, returns a value, and then closes the //stream//. //var// is bound to the value of //stream//, and then //forms// are executed as an //[[CL:Glossary:implicit progn]]//. //stream// is automatically closed on exit from **with-open-stream**, no matter whether the exit is normal or abnormal. The //stream// has //[[CL:Glossary:dynamic extent]]//; its //[[CL:Glossary:extent]]// ends when the //[[CL:Glossary:form]]// is exited. The consequences are undefined if an attempt is made to //[[CL:Glossary:assign]]// the the //[[CL:Glossary:variable]]// //var// with the //forms//. ====Examples==== <blockquote> (with-open-stream (s ([[CL:Functions:make-string-input-stream]] "1 2 3 4")) ([[CL:Functions:math-add|+]] ([[CL:Functions:read]] s) ([[CL:Functions:read]] s) ([[CL:Functions:read]] s))) <r>6 </r> </blockquote> ====Side Effects==== The //stream// is closed (upon exit). ====Affected By==== None. ====Exceptional Situations==== None. ====See Also==== * **[[CL:Functions:close|Function CLOSE]]** ====Notes==== None. \issue{DECLS-AND-DOC} \issue{WITH-OPEN-FILE-STREAM-EXTENT:DYNAMIC-EXTENT} \issue{WITH-OPEN-FILE-SETQ:EXPLICITLY-VAGUE}