Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
4b000cd8
Kaydet (Commit)
4b000cd8
authored
Nis 09, 2005
tarafından
Andrew M. Kuchling
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add more text
üst
bdaad8c9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
7 deletions
+29
-7
whatsnew25.tex
Doc/whatsnew/whatsnew25.tex
+29
-7
No files found.
Doc/whatsnew/whatsnew25.tex
Dosyayı görüntüle @
4b000cd8
...
@@ -28,18 +28,40 @@ rationale, refer to the PEP for a particular new feature.
...
@@ -28,18 +28,40 @@ rationale, refer to the PEP for a particular new feature.
%======================================================================
%======================================================================
\section
{
PEP 309: Partial Function Application
}
\section
{
PEP 309: Partial Function Application
}
For programs written in a functional style, it can be useful to
construct variants of existing functions that have some of the
parameters filled in. This is called ``partial function application''.
The new
\module
{
functional
}
module contains a
\class
{
partial
}
class
that provides partial application.
The
\module
{
functional
}
module is intended to contain tools for
The
\module
{
functional
}
module is intended to contain tools for
functional-style programming. Currently it only contains
functional-style programming. Currently it only contains
\class
{
partial
}
, but new functions will probably be added in future
\class
{
partial
}
, but new functions will probably be added in future
versions of Python.
versions of Python.
% XXX write rest of this
For programs written in a functional style, it can be useful to
construct variants of existing functions that have some of the
parameters filled in. Consider a Python function
\code
{
f(a, b, c)
}
;
you could create a new function
\code
{
g(b, c)
}
that was equivalent to
\code
{
f(1, b, c)
}
. This is called ``partial function application'',
and is provided by the
\class
{
partial
}
class in the new
\module
{
functional
}
module.
The constructor for
\class
{
partial
}
takes the arguments
\code
{
(
\var
{
function
}
,
\var
{
arg1
}
,
\var
{
arg2
}
, ...
\var
{
kwarg1
}
=
\var
{
value1
}
,
\var
{
kwarg2
}
=
\var
{
value2
}
)
}
. The resulting
object is callable, so you can just call it to invoke
\var
{
function
}
with the filled-in arguments.
Here's a small but realistic example:
\begin{verbatim}
import functional
def log (message, subsystem):
"Write the contents of 'message' to the specified subsystem."
print '
%s: %s' % (subsystem, message)
...
server
_
log = functional.partial(log, subsystem='server')
\end{verbatim}
Here's another example, from a program that uses PyGTk.
% XXX add example from my GTk programming
% XXX add example from my GTk programming
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment