What does Python fix?

François Pinard pinard at iro.umontreal.ca
Fri Jan 18 19:34:20 EST 2002


[Huaiyu Zhu]

> > Even if it was possible to purely rely on indentation, the code would
> > use a lot more vertical space, as the current LISP notation is rather
> > compact.  This bloat will not be welcome.

> Example please?

Oh, I've nothing very precise in head.  Yet, consider:

   ((if a b c) (if d e f) (if g h i) (if j k l) (if m n o))

for a trivial skeleton of an example.  Or if you feel induced by the
above example into discussing that Python should have if-expressions
(which it does not really need needed in my opinion), just replace each
`if' by more complex 'cond'.

I also include below a little Scheme example randomly taken from my older
things, which uses enclosed functions.  Such things may surely all been
written in Python, but probably not so compactly.  I'm not really seeking
an argument or fight here, just sharing an intuition.


    ;; ...

    (define (modify redo undo focuses)
      (and pos-flag (warning (_"Read-only in positioning mode")))
      (letrec ((redo-function (lambda () (redo) (cons undo-function focuses)))
	       (undo-function (lambda () (undo) (cons redo-function focuses))))
	(redo)
	(set! redo-list '())
	(set! undo-list (cons undo-function undo-list))))

    (define (undo)
      (and (null? undo-list) (warning (_"No more undo!")))
      (let ((pair ((car undo-list))))
	(set! focus-list (cdr pair))
	(set! redo-list (cons (car pair) redo-list))
	(set! undo-list (cdr undo-list))))

    (define (redo)
      (and (null? redo-list) (warning (_"No more redo!")))
      (let ((pair ((car redo-list))))
	(set! focus-list (cdr pair))
	(set! undo-list (cons (car pair) undo-list))
	(set! redo-list (cdr redo-list))))

    (define (replace value focuses)
      (let ((restore (car focuses)))
	(if (null? (cdr focuses))
	    (let ((point focuses))
	      (modify (lambda () (set-car! point value))
		      (lambda () (set-car! point restore))
		      focuses))
	    (let ((point (cadr focuses))
		  (pos (current-index)))
	      (modify (lambda () (c-set! point pos value))
		      (lambda () (c-set! point pos restore))
		      (cdr focuses))
	      (set-car! focuses value)))))

    ;; ...

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard





More information about the Python-list mailing list