4 ms·
"There is no way to do this in a non Lisp language." Wow. Is it any wonder that you cannot convince someone to use Lisp, when you have no idea what other lang
by teilo 16y ago
"There is no way to do this in a non Lisp language."
Wow.
Is it any wonder that you cannot convince someone to use Lisp, when you have no idea what other languages actually have to offer?
Python 2.6 has a built-in "with" construct for this. Java, C#, earlier versions of Python and (gasp!) VB have the try, catch, finally construct. Offhand, I can't think of a language that can't do this, but I'm sure they exist.
- js2 16y agothis is in reference to macros, of which "with-net-file" is just an example.
- teilo 16y agoNo, it's not: "There is no way to do this in a non Lisp language. The closest you can come is to create an object whose constructor sends the open command and destructor sends the closed command, but even this approach has problems." Seems pretty clear he's talking about the opening/creating and closing/destroying resources.
- js2 16y agoI chalk it up to poor writing. The article clearly makes no sense in that context.
- chc 16y agoHow does catching exceptions absolve us of the need to remember to close files?
- teilo 16y agoThis isn't about exceptions, though it is certainly part of the problem. Try, catch, finally blocks are commonly used to ensure that resources are released once they are no longer used. It not only forces you to remember to close the resources, it also forces you to think about what happens if something in your code breaks, and you have these open resources still in use. It's practically the entire reason that the "finally" block exists.
- ScottBurson 16y agoNo, you're conflating two features. He's not talking about `unwind-protect', which he hasn't even used in his example (that would be the equivalent of `try' ... `finally'). He's talking about the fact that in Lisp, you can make a single abstraction that encapulates the entire pattern of opening the file before doing something and closing it afterwards. This is not that common a language feature, though it is catching on. Python's `with' was introduced in 2.5, which came out a few months after his post was written. Scala's "automatic closures" (I would say "automatic lambdas") show another way to provide this functionality, more general than Python's `with'; I think the blogger can be forgiven for not having heard of Scala in 2006. Java has no elegant way to do this.
- teilo 16y agoThank you. I appreciate the correction and clarification.