Named Functions


;; named fuctions (defun)
(defun hello ()
  "Say hello."
  "hello")

(defun hello (name)
  "Say hello to NAME."
  (format t "Hello ~a!" name)
  name)

;; optional arguments
;; usage: (hello "pwat" t)
(defun hello (name &optional happy)
  "Say hello to NAME."
  (format t "Hello ~a!" name)
  (if happy
      (format t " :) ")
      (format t " :(( ")))

;; key arguments: nil by default, but you can change default values
;; usage: (hello "pwat" :happy t)
(defun hello (name &key (happy t))
  "Say hello to NAME."
  (format t "Hello ~a!" name)
  (if happy
      (format t " :) ")
      (format t " :(( ")))

;; rest: variadic number of arguments
(defun mean (x &rest numbers)
  "Compute the mean of X and other NUMBERS"
  (/ (apply #'+ x numbers)
     (1+ (length numbers))))