try(Writer f = new PrintWriter("foo.txt")) {
f.println("hello, world");
}
try(BufferedReader f = new BufferedReader(new FileReader("foo.txt"))) {
println(f.readLine());
} try(Writer f = new PrintWriter("foo.txt")) {
f.println("hello, world");
}
try(BufferedReader f = new BufferedReader(new FileReader("foo.txt"))) {
println(f.readLine());
}The Java try-with-resources was introduced in Java 7 (2011).
The Python with statement was introduced in Python 2.5 (2006).
The Lisp with-open-file has been in Common Lisp Hyperspec for a long time (1960s?).
Not that it takes anything away from Java. I think all languages are gradually converging to the features of Lisp.
C? No, though I don't really think of that as an actively maintained language. C++ and Perl achieve the same thing via RAII.
> Not that it takes anything away from Java. I think all languages are gradually trying to or discovering the approach the features and expressiveness of Lisp.
I think language design converges over time, alternating between expressive-but-unmaintainable and structured-but-too-strict but getting closer to the ideal as we advance. In many ways Lisp isn't a complete language design at all - rather macros are there for the user to finish the language themselves.
Why would you think that? Work on the C standard is ongoing: http://www.open-std.org/jtc1/sc22/wg14/
Oh, were it only so! It's an actively diddled language.
Common Lisp The Language was published in 1984, CLtL2 in 1990, and the ANSI standard in 1994. I believe the hyperspec (which is not the spec) was published in 1996 or so.
CL is neither as ahead of its time or of another, past time as you might think.
I believe the latest version of Java would allow "var", fwiw.
> Or wrap an object in another object.
True. The java standard library's I/O functionality is quite low-level, perhaps excessively so. In practice there are libraries that give a more lightweight/high-level interface.
While Python gained type hinting. It's funny how in the end stuff converge.