The short answer here is that we don't need to tag functions in the way you described. The C family of languages, for example, typically does something like
type functionName(args...) {...}
where there is no fn
, function
, func
, or anything similar.
Some languages, like Haskell and OCaml, allow for an even more terse syntax.
In both languages, you can create a function with something like
let myFn arg1 arg2 ... argN = ...
and you could call it later just by writing
myFn 10 11 12 ... 50
(imagine our function accepts natural numbers).
Depending on the language and the grammar, the function keyword might be there to avoid ambiguities and simplify parsing. Given enough engineering effort, though, I would assume it to be possible for many languages to get rid of their respective function keywords. So, in my opinion, the answer boils down to this: those keywords are there to help you, not the compiler.
Here is another example, in the untyped lambda calculus. I am going to leave
out the $\lambda$ symbol (which is equivalent to fn
or func
in other languages, but not necessary for parsing). You try to tell me what is going on.
n.f.x.n(g.h.h(g f))(u.x)(u.u)
Admittedly, this would be difficult to unpack in normal lambda calculus, but in this form, it is even harder. (It is the predecessor function for Church encoded numerals, if you're curious).
Anyway. It is there to help you, not the compiler.
sh
, you can't have afunction
keyword and have to define functions like you describe with just the name.bash
andzsh
added the ability to also usefunction
keyword to make the code clearer to read. $\endgroup$C
you can just sayvoid MyFunction() {}
and it recognises it as a function. So I don't think it'shard
for a compiler/interpreter to parse a function, it just might not be as readable on some languages. $\endgroup$