7
$\begingroup$

We have operator and operands, function and formal arguments. Is the difference purely lexical (we use alphanumerics for funciton identifiers but identify operators with special characters, e.g. "+" and ">=") or it is syntactical, like I guessed here

f(a,b) -- prefix notation used for functions
a.f(b) -- infix notation for method invocation (used in OOP)
a f b  -- infix notation without dot and parenthesis used in operator invocations

so that when we write a + b we have an operator but "+"(a, b) (both ways are acceptable in VHDL) makes it a function? Do tools treat them differently? Can you differentiate them? Can you say that this is not a function, it is an operator or vice-verse? When I read the definitions in wikipedia, I do not see that syntax is a distinguishing feature of a concept. So, is it right that operators and functions are synonyms, two different words for the same thing, same meaning, same notion? I have such guess but have never seen it stated explicitly. Please agree with my guess or say what is the difference.

$\endgroup$
4
  • 1
    $\begingroup$ What is your context? I don't think there is a general answer. For example, integer + is an operator in Java and a method in Scala (which has no operators as such). And in mathematics, I don't think there is a difference. $\endgroup$
    – Raphael
    Oct 14, 2012 at 16:14
  • 1
    $\begingroup$ I think that in mathematics situation is similar to programming: two words for the same thing. Operators might have a flavour of "higher-order functions" there. You see, I tried to ask a specific question in VHDL group but it does not help. I do not think that specialists in some language have a better idea of why they call some thing a function and another operator than answering it in general. So, I ask from computer scientists in general. $\endgroup$
    – Val
    Oct 14, 2012 at 18:44
  • $\begingroup$ But I also welcome if you come up with specific contexts, which are concrete on the topic $\endgroup$
    – Val
    Oct 14, 2012 at 18:58
  • 1
    $\begingroup$ In mathematics, $\mathbb R \to \mathbb R$ is a function, $(\mathbb R \to \mathbb R) \to \mathbb R$ is a functional, and $(\mathbb R \to \mathbb R) \to (\mathbb R \to \mathbb R)$ is an operator. $\endgroup$ Nov 26, 2016 at 12:03

3 Answers 3

8
$\begingroup$

Historically, my guess is that the difference is rooted in how things were (and still are) translated into machine code.

An operator such as addition of integers or exclusive-or of booleans would be translated into one (or few) assembler commands which would be directly executed by the processor (resp. its ALU). It would also be part of the syntax.

A function (or procedure, method), on the other hand, is a subprogram the (main) program would explicitly jump to during execution. That is, a new stack frame is allocated, register values are saved, parameters are passed and only then is the function executed. See here for details. Furthermore, functions are defined by the programmer.

Younger programming languages have introduced more abstraction, partially or totally removing the distinction. In C#, for instance, you can overload operators for your own types. In Scala, there are no operators but only syntactic sugar for binary methods. Once these languages are compiled, though, you can see which language elements are translated to flat instructions and which to subroutine calls. Keep in mind that optimising and/or just-in-time compilers may liberally move between worlds.

$\endgroup$
4
  • $\begingroup$ As I suspected, the answer has no context. The history determines the whole realm of machine languages. $\endgroup$
    – Val
    Oct 14, 2012 at 22:19
  • 4
    $\begingroup$ @Val To complete Raphael's answer, in many modern languages, something is called a function if it has an alphabetical name that's written before the argument and an operator if it's made of punctuation and may be infix or otherwise syntactically special. The distinction is not deep and is language-dependent. $\endgroup$ Oct 14, 2012 at 23:51
  • $\begingroup$ Another viewpoint is that operators are primitive constructs of a language, given meaning as part of that language's formal semantics, whereas a function is defined in the language itself. $\endgroup$
    – gardenhead
    Nov 24, 2016 at 17:46
  • $\begingroup$ @gardenhead That would make terminology very weird in the presence of operator overloading. $\endgroup$
    – Raphael
    Nov 30, 2016 at 14:16
1
$\begingroup$

An operator is typically a short-hand notation of a function. For instance, in C++, for an appropriate object a, "a + b" is equivalent to "a.+(b)". Such an equivalence is often available only for operands/arguments whose data types are natural to such an expression. For instance, for a string object, it may make sense to provide such a short form; but for a person object, it is unlikely to write "person1 - person2" because the expression is not intuitive, and therefore, the subtraction operation would not be provided for the type Person.

$\endgroup$
-2
$\begingroup$

There's is no real difference in computer science. The distinction occurs to those who do lambda calculus. There, the difference is akin to math`s distinction between f(x) and f. Both are functions in some sense, but the latter is the name of the function, while the former is the function itself.

$\endgroup$
9
  • 4
    $\begingroup$ And lambda calculus isn't part of computer science, now? In mathematics, $f$ is the function and $f(x)$ is the value to which it maps $x$. And, in any case, what does this have to do with the distinction between functions and operators. $\endgroup$ Nov 26, 2016 at 13:14
  • $\begingroup$ @DavidRicherby: It has to do with names. You are silently applying f(x) to a value, but as it is written on a page it is another set of symbols. See Wittgenstein. $\endgroup$
    – theDoctor
    Nov 27, 2016 at 22:21
  • $\begingroup$ No, I'm not "silently applying $f(x)$ to a value": I'm explicitly applying $f$ to the value $x$. $f(x)$ is a value, so I can't apply it to some other value. Wittgenstein wrote quite a bit, so I'm gonna need a specific reference. $\endgroup$ Nov 27, 2016 at 22:32
  • $\begingroup$ @DavidRicherby: Listen, f(x) maps x to a value. But "f(x)" does not. Get it? $\endgroup$
    – theDoctor
    Nov 27, 2016 at 23:43
  • 3
    $\begingroup$ No, I don't get it at all. Perhaps I'd get it if you actually tried to explain it, instead of making cryptic remarks. I'm not aware of any use of quotation marks in mathematics so claimin that a string of symbols means one thing if it's in quote marks and another thing if it isn't doesn't seem to be a statement about mathematics. $\endgroup$ Nov 27, 2016 at 23:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.