Is there any difference between the terms "call", "invoke" or "apply" a function?

Asked

Viewed 113 times

3

I commonly read the term "invoke" or "call for" a function to refer to the action of executing that function. But I may also read the term "apply".

In my view, all three of these terms have the same meaning, that’s right?

Is there any semantic difference or special meaning that differentiates these three terms, or is it all the same thing? I would also like to know if, in addition to these three, there is any other way to refer to the action of performing a function (apart from these three terms)?

1 answer

3


I have never seen a clear formal definition of this, but in fact the terms are used in different contexts, although in practice it makes no difference. It has been agreed to use different terms when the execution is done differently.

And this can vary from language to language according to the adopted culture. And I get the impression that you’re asking this more because of Javascript that actually uses these terms in methods that make function calls. If you’re gonna talk about it, there’s a reply on Soen which justifies the difference between the methods, then only to leave complete. Because JS have no function overload had to give different names because of the parameters, otherwise nothing would prevent using the same name.

But considering only the very terms, in an answer from me I talk a little about the importance of giving the correct name. What for us Portuguese speakers can be a little more difficult to use in English. Even in English the normal is to use a similar word as if it were a pure synonym.

I looked for some things and found nothing that convinces me, for example: https://stackoverflow.com/q/50884893/221800 speaks of other things or speculation.

You can think of several terms that could be used, some less appropriate, but in practice do the same thing: run, request, demand or start (yes I can see some sense in certain contexts, although they may be more specific) would be some of them.

Call, invoke or apply may give some better indication according to the context as well, but for the pure function I see difficulty in distinguishing. And I think it’s best to use the English terms, because in Portuguese can give a slightly different semantics than is usually used in programming. And so I won’t even put the definition that is usually given in Portuguese of each word.

  • Call - asks for something to happen or answer
  • Invoke - will use something that gives a result that is expected
  • Apply - asks for something formally

Browser other questions tagged

You are not signed in. Login or sign up in order to post.