Plotting Functions

Plotting the sine functions in the previous section was a bit cumbersome. As an alternative we can use the function "2D plot-function to plot a function of one argument over a specified range. We can plot the sine function using the expression
(plot-function (function sin) (- pi) pi)

The expression "2D (function sin) is needed to extract the function associated with the symbol "2D sin. Just using "2D sin will not work. The reason is that a symbol in Lisp can have both a value, perhaps set using "2D def, and a function definition at the same time. 5 This may seem a bit cumbersome at first, but it has one great advantage: Typing an innocent expression like

(def list '(2 3 4))
will not destroy the "2D list function.

Extracting a function definition from a symbol is done almost as often as quoting an expression, so again a simple shorthand notation is available. The expression

#'sin
is equivalent to the expression "2D (function sin). The short form "2D #' is usually pronounced sharp-quote. Using this abbreviation the expression for producing the sine plot can be written as
(plot-function #'sin (- pi) pi)