Why is Python popular, while Lisp and Scheme aren't?

Bengt Richter bokr at oz.net
Wed Nov 13 13:09:01 EST 2002


On Wed, 13 Nov 2002 11:19:39 GMT, Alex Martelli <aleax at aleax.it> wrote:
[...]
>
>I've found myself wishing for "set-and-test" basically in ONE
>kind of situation: when I was transcribing algorithms coded in
>languages that used that form, such as C.  In such cases, of
>course, it's trivially easy to build and use set-and-test, see:
>
>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66061
>
I prefer the leaner expressions you get using a value grabber
something like (snipped from another post):

 >>> class V:
 ...     def __init__(self, v=None): self.v = v
 ...     def __call__(self, *v):
 ...         if v: self.v = v[0]
 ...         return self.v
 ...
 >>> v=V()

Then you can write stuff like

     if v(expression): 	   # saves value and tests
         print v()	   # uses the value
     elif v(other_expression):
         s = v().group(1)  # etc

or choose your own in place of v for a better mnemonic, to suit taste.

Regards,
Bengt Richter



More information about the Python-list mailing list