Make $ a valid identifier and a singleton
Make $ a valid identifier and a singleton. $ is a useful placeholder in []. Possible function partial syntax: def foo(x, y): print(x, y) partialized = foo[$, 10] partialized(5) # => 5 10
I used "..." in my lib to do that :
from funcoperators import bracket
@bracket
def foo(x, y):
print(x, y)
partialized = foo[..., 10]
partialized(5)
https://pypi.org/project/funcoperators/
Le dim. 23 juin 2019 à 21:34, James Lu
Make $ a valid identifier and a singleton.
$ is a useful placeholder in [].
Possible function partial syntax:
def foo(x, y):
print(x, y)
partialized = foo[$, 10]
partialized(5)
# => 5 10
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/V7ZCLM... Code of Conduct: http://python.org/psf/codeofconduct/
On Sun, Jun 23, 2019 at 03:22:37PM -0400, James Lu wrote:
Make $ a valid identifier and a singleton.
$ is a useful placeholder in [].
Possible function partial syntax:
def foo(x, y): print(x, y)
partialized = foo[$, 10]
I don't think that creating partial functions is important enough to: 1. make partial functions a built-in language feature; 2. using syntax (square brackets); 3. and require a new built-in singleton. I think that functools.partial is missing two features: - the ability to close over positional parameters from the right, rather than the left; - the ability to skip parameters. The first could be solved with a "rpartial" function, and the second by using ellipsis ... as a placeholder, or a named constant in the functools module. -- Steven
On Jun 23, 2019, at 17:01, Steven D'Aprano
On Sun, Jun 23, 2019 at 03:22:37PM -0400, James Lu wrote: Make $ a valid identifier and a singleton.
$ is a useful placeholder in [].
Possible function partial syntax:
def foo(x, y): print(x, y)
partialized = foo[$, 10]
I don't think that creating partial functions is important enough to:
1. make partial functions a built-in language feature; 2. using syntax (square brackets); 3. and require a new built-in singleton.
I think that functools.partial is missing two features:
- the ability to close over positional parameters from the right, rather than the left;
- the ability to skip parameters.
The first could be solved with a "rpartial" function, and the second by using ellipsis ... as a placeholder, or a named constant in the functools module.
I’m pretty sure there are multiple improved-partial projects on PyPI. Maybe just picking out one and adding a link to it from the functools docs is sufficient?
participants (4)
-
Andrew Barnert
-
James Lu
-
Robert Vanden Eynde
-
Steven D'Aprano