Re: replace() and replace-with()

> Is this definition of one function or of four functions? If this is a definition of one function, then how do we know that we have seen all of the definitions (maybe there are more than 4 definitions, but they are scattered across the code and we cannot be aware of all of them)? 

It is one function. The arity is two. All the keyword arguments in the call are combined into a single map value passed to the function
> What is the arity of the function: 2 or 3 or 4 or 5 or 6? If the answer is 2, how can you explain to a developer that in all the above cases they are calling a 2-argument function, when they in fact are literally specifying 3 and 4 arguments?

It depends on the developer. If they use Python, they will already be familiar with the idea of ** arguments:

def intro(**data):
    print("\nData type of argument:",type(data))

    for key, value in data.items():
        print("{} is {}".format(key,value))

intro(Firstname="Sita", Lastname="Sharma", Age=22, Phone=1234567890)
intro(Firstname="John", Lastname="Wood", Email="", Country="Wakanda", Age=25, Phone=9876543210)
(Here type(data) outputs <class dict>)

If they're familiar with varargs in Java, then I would explain it as saying it's very similar to varargs: there's one parameter defined in the declaration, which receives a composite value from several arguments supplied independently in the call.  

> What if some of the keyword arguments are mutually exclusive and thus shouldn't be specified together on the same function call? Or if we have two different subsets of keyword arguments that are mutually exclusive? How can one specify this formally?
We could try and add that mechanism, but I think it's probably OTT. I don't see such a mechanism in Python, for example. It's not unusual to have preconditions on the valid arguments for a function beyond those that can be expressed formally in the function signature.

> Such deep changes need scrupulous attention and discussion, so, please, go gradually, patiently, step by step, and only proceed deeper if you have got a near-consensus at the current step.

Personally, I find it hard to assess the steps without seeing where they lead. I can only judge whether the feature seems to "work" by defining it fully and trying it out. The only way to judge whether this mechanism for keyword arguments is useful is to design some functions that take advantage of it and see whether they appear usable. That's what I've been trying to do.

Michael Kay

Received on Thursday, 3 December 2020 16:04:08 UTC