Most of the functions we would like to write is going to be a lot longer than
the double function.
A D V E R T I S E M E N T
When working with complex programs, it is usually
desirable to edit the program with an editor, fully debug the code, and then
compile it for faster performance. Use your favorite text editor (mine is
emacs) to key in the following function definition:
;;; by Philip Fong
;;; Introductory comments are preceded by ";;;"
;;; Function headers are preceded by ";;"
;;; Inline comments are introduced by ";"
;; Triple the value of a number
(defun triple (X)
"Compute three times X." ; Inline comments can
(* 3 X)) ; be placed here.
;; Negate the sign of a number
(defun negate (X)
"Negate the value of X." ; This is a documentation string.
Save the above in the file testing.lisp. Now load the definition into
the LISP environment by typing:
USER(5): (load "testing.lisp")
; Loading ./testing.lisp
Let us try to see if they are working properly.
USER(6): (triple 2)
USER(7): (negate 3)
When functions are fully debugged, we can also compile them into binaries:
USER(8): (compile-file "testing.lisp")
Depending on whether your code is well-formed, and what system you are using,
some compilation messages will be generated. The compiled code can be loaded
into the LISP environment later by using the following:
USER(9): (load "testing")
; Fast loading ./testing.fasl