Closures python,scheme,ruby
Michele Simionato
michele.simionato at gmail.com
Mon Jul 12 11:12:14 EDT 2004
paolo veronelli <paolo_veronelli at yahoo.it> wrote in message news:<mailman.250.1089623585.5135.python-list at python.org>...
> I've a vague idea of the differences,I don't know scheme anyway.
>
> I'd like to see an example to show what is missing in python about
> closures and
> possibly understand if ruby is better in this sense.
>
> Iuse ruby and python in parallel for my job just to learn them and their
> differences and python is shorter and cleaner ,but i feel it's missing
> something,
> in closures.Any hints?
>
> grazie Paolino
Python is cleaner but not shorter ;) I don't know about closures in Ruby,
the basic difference between Python and Scheme is that Python
closures are read-only, whereas Scheme closures are read-write
(Scheme has a set! primitive). Here is an example:
(define (outer)
(let ((x 1))
(lambda () (set! x 2) x)))
((outer))
2
You cannot do that in Python, unless you use ugly tricks with mutable objects.
Michele Simionato
More information about the Python-list
mailing list