defun name lambda-list [[ {declaration}* | doc-string ]] {form}*
what means:
(defun < function-name > (< arg-1 > < arg-2 > ... < arg-n >)
"documentation string"
< lisp-forms > )
(defun harmonic-series (frequency n)
;;; Documentation String
"prints the harmonic-series with fundamental < frequency >
and < n > harmonics"
;;; Body
;;; First Form
(loop for j from 1 to n do
(print (* frequency j)))
;;; Second Form
'done)
(harmonic-series 440 5.0)
\_/ \_/
| n
frequency
(documentation 'harmonic-series 'function)
(defun harmonic-series (frequency n &optional (ratio 1))
"prints the harmonic-series with fundamental < frequency >
and < n > harmonics at a ratio of < ratio >"
(loop for j from 1 to n and for r from 1 by ratio do
(print (* frequency r)))
'done)
(harmonic-series 440 5)
(harmonic-series 440 5 (expt 2 1/2))
(defun harmonic-series (frequency n &optional (ratio 1)(sel nil))
"prints the harmonic-series with fundamental < frequency >
and < n > harmonics at an optional ratio of < ratio >.
The < sel > optional must be 'odd or 'even"
(if sel
(if (equal sel 'even)
(loop for j from 1 to n and for r from 2 by (* 2 ratio) do
(print (* frequency r)))
(if (equal sel 'odd)
(loop for j from 1 to n and for r from 1 by (* 2 ratio) do
(print (* frequency r)))
(error "sel must be 'odd or 'even")))
(loop for j from 1 to n and for r from 1 by ratio do
(print (* frequency r)))))
(harmonic-series 440 5 1 'odd)
(harmonic-series 440 5 1 'even)
(harmonic-series 440 5 1 'all)
(defun harmonic-series (frequency n &key (ratio 1)(sel nil)(start 1))
"returns a list of the harmonic-series with fundamental < frequency >
and < n > harmonics. Key arguments: < ratio > < sel >
(must be 'odd or 'even), < start >"
(let ((output-list nil))
(if sel
(if (equal sel 'even)
(loop for j from 1 to n and for r from (+ start 1) by (* 2 ratio) do
(push (* frequency r) output-list))
(if (equal sel 'odd)
(loop for j from 1 to n and for r from start by (* 2 ratio) do
(push (* frequency r) output-list))
(error "sel must be 'odd or 'even")))
(loop for j from 1 to n and for r from start by ratio do
(setf output-list (push (* frequency r) output-list))))
(reverse output-list)))
(defun harmonic-series (frequency n &key (ratio 1)(sel nil)(start 1) &aux (output-list nil))
"returns a list of the harmonic-series with fundamental < frequency >
and < n > harmonics. Key arguments: < ratio > < sel >
(must be 'odd or 'even), < start >"
(if sel
(if (equal sel 'even)
(loop for j from 1 to n and for r from (+ start 1) by (* 2 ratio) do
(push (* frequency r) output-list))
(if (equal sel 'odd)
(loop for j from 1 to n and for r from start by (* 2 ratio) do
(push (* frequency r) output-list))
(error "sel must be 'odd or 'even")))
(loop for j from 1 to n and for r from start by ratio do
(setf output-list (push (* frequency r) output-list))))
(reverse output-list))
some calls to the function:
(harmonic-series 440 5 :ratio 1 :start 15)
(harmonic-series 440 5 :ratio 1 :start 15 :sel 'odd)
(harmonic-series 440 5 :ratio (expt 2 1/2) :sel 'even)
(harmonic-series 440 5 :start 10)
(+ 1 2)
(+ 1 2 3 4 5)
(+ 1 2 3 4 5 6 7 8 9 10 11)
(defun pitch-list (&rest note-list)
"returns a list with the frequencies
of the notes passed as arguments"
(let ((out-list nil))
(dolist (i note-list)
(push (pitch i) out-list))
(reverse out-list)))
(pitch-list 'c4 'e4 'g4 'c5)
(pitch-list 'c4 'ef4 'g4)
(pitch-list 'GS8 'AS8 'C9 'D9 'DS9 'F9 'FS9 'G9 'GS9 'AS9)
(defun harmonic-series (frequency n &key (ratio 1)(sel nil)(start 1)(notes nil) &aux (output-list nil))
"returns a list of the harmonic-series with fundamental < frequency >
and < n > harmonics. Key arguments: < ratio > < sel >
(must be 'odd or 'even), < start >"
(if sel
(if (equal sel 'even)
(loop for j from 1 to n and for r from (+ start 1) by (* 2 ratio) do
(push (* frequency r) output-list))
(if (equal sel 'odd)
(loop for j from 1 to n and for r from start by (* 2 ratio) do
(push (* frequency r) output-list))
(error "sel must be 'odd or 'even")))
(loop for j from 1 to n and for r from start by ratio do
(setf output-list (push (* frequency r) output-list))))
(if notes (reverse (mapcar #'note (mapcar #'float output-list)))
(reverse output-list)))
(mapcar #'float '(1 2 3))
(harmonic-series 440 5 :notes t)
(defun harmonic-series (frequency n &key (ratio 1)(sel nil)(start 1)(notes nil) &aux (output-list nil))
"returns a list of the harmonic-series with fundamental < frequency >
and < n > harmonics. Key arguments: < ratio > < sel >
(must be 'odd or 'even), < start >, < notes >"
(if sel
(if (equal sel 'even)
(loop for j from 1 to n and for r from (+ start 1) by (* 2 ratio) do
(push (* frequency r) output-list))
(if (equal sel 'odd)
(loop for j from 1 to n and for r from start by (* 2 ratio) do
(push (* frequency r) output-list))
(error "sel must be 'odd or 'even")))
(loop for j from 1 to n and for r from start by ratio do
(setf output-list (push (* frequency r) output-list))))
(if notes (reverse (mapcar #'(lambda (x)
(note (float x)))
output-list))
(reverse output-list)))
(harmonic-series 440 5 :notes t)
©1996-98 by Juan Pampin, juan@ccrma.stanford.edu