Here's how to define a simple LISP function ```lisp (defun pi () "A sample non-interactive function" 3.1415) ``` The above is a non-interactive function that simply returns 3.1415. Evaluate it (`C-x C-e`, remember?) and you will see the word pi appear in the echo area. Try `M-x pi`, though, and Emacs won't find the function. If you want to be able to call a function using M-x, you have to make it interactive, as follows. ```lisp (defun print-pi() "Insert an approximation to pi" (interactive) (insert "3.1415")) ``` So why would you want a non-interactive function? Perhaps because you want it to be called from another function, as follows: ```lisp (defun circumference-of-circle() (interactive) (message "The circumference of a circle diameter 3 is %f" (\* pi 3))) ``` Before evaluating the above function, make sure that you have evaluated the non-interactive function pi. There are lots of different types of interactive functions. The next interactive function is more useful in that it prompts for the diameter to be input (the n at the start of "nInput diameter of circle:" is what tells Emacs to prompt for a number) ```lisp (defun circumference-of-circle(diameter) "Calculate the circumference of a circle given the diameter" (interactive "nInput diameter of circle:") (message "The circumference of a circle diameter %d is %f" diameter (\* 3.1415 diameter))) ``` Here's the same function but this time set up to receive the parameter from the universal argument. That is to say, in the form `C-u 4 M-x circumference-of-circle`. ```lisp (defun circumference-of-circle(diameter) (interactive "p") (message "The circumference of a circle diameter %d is %f" diameter (\* 3.1415 diameter))) ``` Here's an example of a function that reads strings and tests your knowledge of capital cities. ```lisp (defun capital-of-france(answer) "Simple quiz example." (interactive "sWhat's the Capital of France?") (if (string= answer "paris") (message "Correct!") (message "Wrong!"))) ``` Argument codes for interactive functions can be found [here](http://www.gnu.org/software/emacs/manual/html_node/elisp/Interactive-Codes.html#Interactive-Codes) # Next [[3 Interactive Functions that work on Regions]]