News for hackers. Stuff that matters.
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"
        ].

There are no comments on this comment yet.