2 ms·
This "thing that can't be done in any other language" looks an awful lot like RAII in C++. For example I can write: { ifstream file("filename"); ...
by CJefferson 16y ago
This "thing that can't be done in any other language" looks an awful lot like RAII in C++.
For example I can write:
{
ifstream file("filename");
...
} // file closed here automatically.
or
{
mutex_grab g(mutex);
.....
} // mutex automatically released here
- stcredzero 16y agoIn 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" ].