4 ms·
And now no one can forget to close the file, plus it’s shorter as well. There is no way to do this in a non Lisp language. C# has the IDisposable + using const
by barrydahlberg 16y ago
And now no one can forget to close the file, plus it’s shorter as well. There is no way to do this in a non Lisp language.
C# has the IDisposable + using construct for exactly this purpose. If you're not happy with that you can write your own using a lambda, just like his example...
using (open file here)
{
// Do work here
}
WithNetFile(f => do work here);
Lisp is neat, this is not a great argument though.
- js2 16y agoThe this the original author is referring to is macros, of which, with-net-file is merely an example. The author makes this clear later in the post: "Once you have caught the programmer’s interest with simple macros show them some other cool things they can do, like language extensions. Experienced programmers are always looking for more control, and macros give it to them."
- barrydahlberg 16y agoYes, but he is giving this as an example of how to hook programmers into learning Lisp. I'm all on board with the macros, but you have to do better than this as an argument.