Re:Convincing Programmers They Want To Use Lisp
by stcredzero on Monday February 21, 2011 @04:44PM
(#2247338)
In Smalltalk, it's just a normal function you can add to Filename:
doWithStreamThenClose: aBlock
| fileStream |
fileStream := self newReadWriteStream.
^[aBlock value: fileStream]
ensure: [fileStream close]
This allows one to do: (Filename named: 'mypath/foo.dat')
doWithStreamThenClose: [ :fileStream |
"do whatever you want with fileStream"
"it shall be closed"
].
For example I can write:
or