missing 'xor' Boolean operator

Tim Wintle tim.wintle at teamrubber.com
Wed Jul 15 05:28:34 EDT 2009


On Wed, 2009-07-15 at 02:02 -0700, Jonathan Gardner wrote:
> On Jul 14, 4:48 pm, Ethan Furman <et... at stoneleaf.us> wrote:
> >
> > A whole family of supers.  :)
> >
>  All the things binary operators can do, Lisp
> does with 0, 1, 2, or more arguments.

+1

n-ary operators are great, but binary operators are just syntactic sugar
for functions (which are obviously a generalisation of an n-ary operator
in python).

The fact that lisp-like languages don't expose this sugar is good for
making you think about what you're actually doing, but just like
mathematicians use binary (and unary) operators in equations rather than
working in the lambda calculus, having that sugar is useful to python.

> 
> [1]> (+)
> 0
> [2]> (+ 1)
> 1
> [3]> (+ 1 2)
> 3
> [4]> (+ 1 2 3)
> 6

c.f. :

>>> sum([])
0
>>> sum([1])
1
>>> sum([1,2])
3
>>> sum([1,2,3])
6



> Once you get used to that, binary operators don't seem so useful
> anymore.
> 
> The equivalent in Python is dropping the operators and replacing them
> with built-in functions that take 0, 1, 2, or more arguments.




More information about the Python-list mailing list