What does Python fix?

Jason Orendorff jason at jorendorff.com
Sat Jan 19 13:48:57 EST 2002


Francois Pinard wrote:
> > def modify(redo, undo, focuses):
> This might not work, I'm not sure. [...]

It works in Python 2.2.  Python has closures now.

> > def undo():
> >     if len(undo_list) == 0:
> >         warning(_("No more undo!"))
> >     redo_fn, focus_list[:] = undo_list.pop()()
> >     redo_list.append(redo_fn)
> 
> I'm only worried a bit by the replacement of the whole focus_list, not
> knowing how efficient such an operation is.  [...]

You're right.  Instead:
    global focus_list                          # clearer...
    redo_fn, focus_list = undo_list.pop()()    # ...and faster

As for the semantics of replace(), I can't be responsible.  :)
I couldn't tell what 'focuses' was supposed to be.

> [...]
> I still have the overall feeling that, without special care, it 
> is not that easy to write Python code that correctly represents
> the original Scheme.
> It might require more vertical space, including a few more 
> accessory classes.

It is not that easy, true; but the difficult part is
figuring out what the Scheme code is intended to do.
Even clear and elegant code, such as yours, can be hard
to decipher without any comments.

I'm completely confident that the Scheme translates to
a roughly equal amount of Python code.  No accessory classes
are required.  But alas, nothing can be done about a person's
overall feelings.  :)

## Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list