I don't know if this has been suggested before, or if this is outlandishly 
impossible (though I would be surprised if it was), so apologies in advance if 
so.

I have on occasion come across a situation where I use/write a signature like 
this:

    def insert_x_into_y(x, y):
        ...

or worse
    
    def insert_into(item, container):
        ...

where, despite a driving idea of python syntax being readability in english, 
the function signature is distinctly not english.
"I'll just go and insert into this item that container", is not only never said 
but is actually ambiguous in english.

What would be really cool, is if python let you write function signatures like 
this:

    def insert_(item)_into_(container):
        ...

where the arguments dispersed between the function name are positional only 
argument, and any key word arguments would have to go at the end.
It would create a function that could be called as:

    insert_(1)_into_(my_list)
    
or

    insert__into_(1, my_list)
    
The purpose of allowing both should be obvious - so that the function can be 
referenced and called in other places.
(Rather than just skipping the brackets the function call with only the end 
parentheses could have a special stand in character e.g. ., ?, !, _ or other if 
that was more preferred.)

This sort of signature is particularly annoying for boolean checks like 
`isinstance` (N.B. I am _not_ suggesting changing any builtins), which one 
could wrap with:

    def is_(obj)_an_instance_of_(type):
        return isinstance(obj, type)

For precedence in other languages, this is similar to curried functions in 
functional languages e.g Haskell, especially if each part of a function were to 
be callable, which would be up for debate.

Allowing each part to be called would make sense if each "next" partial 
function were an attribute on the previous and what it returned, making it a 
sort of object oriented currying. 
Then the syntax could be with a `.`:

    def is_(obj)._an_instance_of_(type):
        ...

    is_(1)._an_instance_of_(int)
    is_._an_instance_of_(1,int)
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/YMFRX6K22TZNNAP2PPVV7RGNI5HLC764/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to