[Python-checkins] python/nondist/peps pep-0336.txt, NONE,
1.1 pep-0000.txt, 1.293, 1.294
goodger at users.sourceforge.net
goodger at users.sourceforge.net
Wed Nov 3 17:58:32 CET 2004
Update of /cvsroot/python/python/nondist/peps
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20583
Modified Files:
pep-0000.txt
Added Files:
pep-0336.txt
Log Message:
added PEP 336, "Make None Callable", by Andrew McClelland
--- NEW FILE: pep-0336.txt ---
PEP: 336
Title: Make None Callable
Version: $Revision: 1.1 $
Last-Modified: $Date: 2004/11/03 16:58:30 $
Author: Andrew McClelland
Status: Draft
Type: Standards Track
Content-Type: text/plain
Created: 28-Oct-2004
Post-History:
Abstract
None should be a callable object that when called with any
arguments has no side effect and returns None.
Motivation
To allow a programming style for selectable actions that is more
in accordance with the minimalistic functional programming goals
of the Python language.
Rationale
Allow the use of None in method tables as a universal no effect
rather than either (1) checking a method table entry against None
before calling, or (2) writing a local no effect method with
arguments similar to other functions in the table.
The semantics would be effectively,
class None:
def __call__(self, *args):
pass
How To Use
Before, checking function table entry against None:
class Select:
def a(self, input):
print 'a'
def b(self, input):
print 'b'
def c(self, input);
print 'c'
def __call__(self, input):
function = { 1 : self.a,
2 : self.b,
3 : self.c
}.get(input, None)
if function: return function(input)
Before, using a local no effect method:
class Select:
def a(self, input):
print 'a'
def b(self, input):
print 'b'
def c(self, input);
print 'c'
def nop(self, input):
pass
def __call__(self, input):
return { 1 : self.a,
2 : self.b,
3 : self.c
}.get(input, self.nop)(input)
After:
class Select:
def a(self, input):
print 'a'
def b(self, input):
print 'b'
def c(self, input);
print 'c'
def __call__(self, input):
return { 1 : self.a,
2 : self.b,
3 : self.c
}.get(input, None)(input)
References
[1] Python Reference Manual, Section 3.2,
http://docs.python.org/ref/ref.html
Copyright
This document has been placed in the public domain.
Local Variables:
mode: indented-text
indent-tabs-mode: nil
sentence-end-double-space: t
fill-column: 70
End:
Index: pep-0000.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0000.txt,v
retrieving revision 1.293
retrieving revision 1.294
diff -u -d -r1.293 -r1.294
--- pep-0000.txt 27 Oct 2004 10:09:55 -0000 1.293
+++ pep-0000.txt 3 Nov 2004 16:58:30 -0000 1.294
@@ -123,6 +123,7 @@
S 332 Byte vectors and String/Unicode Unification Montanaro
S 334 Simple Coroutines via SuspendIteration Evans
S 335 Overloadable Boolean Operators Ewing
+ S 336 Make None Callable McClelland
S 754 IEEE 754 Floating Point Special Values Warnes
Finished PEPs (done, implemented in CVS)
@@ -366,6 +367,7 @@
I 333 Python Web Server Gateway Interface v1.0 Eby
S 334 Simple Coroutines via SuspendIteration Evans
S 335 Overloadable Boolean Operators Ewing
+ S 336 Make None Callable McClelland
SR 666 Reject Foolish Indentation Creighton
S 754 IEEE 754 Floating Point Special Values Warnes
I 3000 Python 3.0 Plans Kuchling, Cannon
@@ -431,6 +433,7 @@
Lielens, Gregory gregory.lielens at fft.be
von Loewis, Martin loewis at informatik.hu-berlin.de
Martelli, Alex aleax at aleax.it
+ McClelland, Andrew eternalsquire at comcast.net
McMillan, Gordon gmcm at hypernet.com
McNamara, Andrew andrewm at object-craft.com.au
Mick, Trent trentm at activestate.com
More information about the Python-checkins
mailing list