Why don't people like lisp?

Matthew Danish mdanish at andrew.cmu.edu
Fri Oct 24 16:21:24 EDT 2003


On Fri, Oct 24, 2003 at 08:00:23PM +0000, Rainer Deyke wrote:
> I DON'T want to manually close files.  I DON'T want to deal with the
> limitations of with-open-file.  And, here's the important bit, I DON'T WANT
> TO COMBINE OR CHOOSE BETWEEN THESE TWO METHODS, BOTH OF WHICH ARE FLAWED.

I already discussed this in another post.

> What I want to open a file and have it close automatically when I am done
> with it.  I can do that in C++.  Why can't I do it in Python?

One major difference between C++ and Lisp/Python is that C++ lacks
closures.  This means that local variables do not have to be considered
for allocation on the heap.  So saying

{
  ofstream f;
  f.open ("output");
  ...
  // I presume ofstream dtor closes file?  I'm a bit rusty
}

is okay in C++ to obtain a similar effect as WITH-OPEN-FILE, though
I am not sure how well it does when it comes to abnormal conditions.

In Common Lisp, and presumably now Python, lexical scope combined with
higher-order functions implies that variables may be captured in a
closure and have indefinite extent.  In CL, also, the language does not
define memory management; leaving open the possibility for a better
solution than GC.  CL's answer to the handling of dynamic-extent
resources is WITH-OPEN-FILE, and also the other operators from which
WITH-OPEN-FILE is defined (such as UNWIND-PROTECT).

One final question: do you expect C++ to clean up dynamically allocated
ofstream objects, automatically?

-- 
; Matthew Danish <mdanish at andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."




More information about the Python-list mailing list