Bill Atkins <[EMAIL PROTECTED]> writes:
> Does Python have any support for closures? If so, ignore this point.
> But if not, what about examples like this:
>
> (defun make-window (window observer)
> ;; initialization code here
> (add-handler window 'close
> (lambda (event)
> (notify observer event)))
> ;; more code)
Python has closures but you can only read the closed variables, not
write them.
> Being able to keep pass around state with functions is useful.
>
> There are also cases where a function is so trivial that the simplest
> way to describe it is with its source code, where giving it a name and
> putting it at the beginning of a function is just distracting and
> time-consuming. E.g.:
>
> (remove-if (lambda (name)
> (find #\- name :test #'char=))
> list-of-names)
If I read that correctly, in Python you could use
filter(list_of_names, lambda name: '-' not in name)
or
[name for name in list_of_names if '-' not in name]
Both of these have become more natural for me than the Lisp version.
--
http://mail.python.org/mailman/listinfo/python-list