Overloading operators for currying, a PEP309 suggestion

Jp Calderone exarkun at intarweb.us
Tue Mar 11 13:32:47 EST 2003


On Tue, Mar 11, 2003 at 03:38:41PM +0100, Bernhard Herzog wrote:
> Stephen Horne <intentionally at blank.co.uk> writes:
> 
> > I would prefer defining the __len__, __getitem__, __setitem__ and
> > __delitem__ methods to allow direct manipulation (and creation and
> > deletion) of the closure.
> 
> That would mean that the length of a function with no arguments is 0,
> right? That's bad and will likely introduce subtle bugs because then all
> functions with no arguments are suddenly considered false.
> 

    >>> class foo(object):
    ...   def __len__(self): return 0
    ...   def __nonzero__(self): return 1
    ... 
    >>> if foo(): print 'evaluates to true'
    evaluates to true


  Jp

-- 
"There is no reason for any individual to have a computer in their
home."
                -- Ken Olson, President of DEC, World Future Society
                   Convention, 1977
-- 
 up 8 days, 9:59, 8 users, load average: 0.00, 0.05, 0.07





More information about the Python-list mailing list