Overriding logical operators?

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Aug 24 06:57:38 CEST 2004


Robert Brewer wrote:
> This has come up before--in particular, I think Greg Ewing was taking a
> stab at it last.

I have some ideas on how it could be done, although I
haven't gotten around to trying them out yet.

Essentially, there would be two special methods corresponding
to each of these, e.g. '__and1__' and '__and2__' etc. The
first operand would be evaluated and passed to __and1__. If
that can determine the result, it returns it, and evaluation of
the other operand is skipped. If not, it returns a special value
(or maybe raises a special exception) which means "other operand
needed". The second operand is evaluated, and both operands are
passed to __and2__, which returns the final result.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list