Although it is very useful to give a function a name, this is not strictly necessary. Giving a function a name is necessary only if we want to repeatedly call that function. We can still create ``anonymous functions'', i.e. functions without names. Such functions are not as totally useless as one might first assume. In lisp, functions are first class objects. This means you can do with (or to) a function what you can do with (or to) a normal type like an integer string. Like pass it as arguments to other functions, return it from functions, assign it to names etc.
The right way to think about a function is as an object containing all the expressions making up the function body. The way to create such an anonymous function object is as follows:
(lambda () (message "Hello World\n") (message "Hello world once again!\n"))
This is the same function we saw in an earlier example. The only difference being that this function has no name. One application of such anonymous functions in Emacs is to assign it to hook variables. Once you create and assign a function object to a hook variable, you, the user, do not need the function, so it does not matter if you do not give it a name. An example of assigning to hook variables is this:
(add-hook 'c-mode-hook
(lambda () (message "Hurrah! I am entering the C mode!!")))