next up previous contents index
Next: More on Generating Up: Elementary Statistical Operations Previous: Exercises

Plotting Functions

Plotting the sine function in the previous section was a bit cumbersome. As an alternative we can use the function 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 (function sin) is needed to extract the function associated with the symbol sin . Just using sin will not work. The reason is that a symbol in Lisp can have both a value , perhaps set using def , and a function definition at the same time. gif 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 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 (function sin) . The short form #' is usually pronounced sharp-quote . Using this abbreviation the expression for producing the sine plot can be written as
(plot-function #'sin (- pi) pi).



next up previous contents index
Next: More on Generating Up: Elementary Statistical Operations Previous: Exercises



Anthony Rossini
Fri Oct 20 10:29:17 EDT 1995