[Python-Dev] bitwise operators and lambdas

Jack Diederich jack@performancedrivers.com
Mon, 10 Feb 2003 10:57:48 -0500


I don't expect action or consensus on these, but I thought I get them on 
record by posting

1) move bitwise operators to a package and deprecate them from the 
   language as special syntax

2) use pipes as shorthand for lambdas

re: 1) bitwise operators

bitwise OR is used on 61 lines in Lib/ out of 70k+ lines. There is nothing 
inheritly un-pythonic about bitwise operators but they don't really come up 
much in a high level language like python.  They just seem 'extra' esp since 
we spell || as 'or' and && as 'and'.   sets are about the only thing to 
usefully define __xor__ and its kind.

re: 2) lambda shorthand

Most people hate lambdas, but I like em.  They would beat listcomps in 
readability if it weren't for the clunky appearance of the string 'lambda' 
everywhere they are used.  People seem to like list comps over filter/map 
mainly because they save keystrokes.

old             shorthand
lambda:foo()    ||foo()
lambda x:foo(x) |x|foo(x)

l = [x.guy for (x) in blah]
l = map(|x|x.guy, blah)

l = [x for (x) in blah if x < 7]
l = filter(|x|x < 7, blah)

l = [x.guy for (x) in blah if x.guy < 7]
l = map(|x|x.guy, filter(|x|x.guy < 7, blah))

I also like the passing-something-on implication of using a pipe character.
Plus I like the left-to-right reading of map/filter over listcomps.

dreaming-of-pytohn-3k-ly,

-jackdied