4 Etudes, Op. 1: The Lisp Listener

Interaction 4-1. Evaluating numbers.

cm> 440
cm> 44100.0

Interaction 4-2. Evaluating symbols.

cm> pi
cm> *scale*
#<tuning "standard-chromatic-scale">
cm> stravinsky
*** - EVAL: variable STRAVINISKY has no value
1. Break [4]> abort

Example 4-1. A Lisp file

;;; This is a sample lisp source file and you are 
;;; reading a Lisp comment.  A comment begins with ;
;;; and continues to the end of the line. Lisp 
;;; ignores comments when it process source code. 
;;; To evaluate a lisp expression inside Emacs,
;;; first select the expression by double-clicking it
;;; and then use the Eval Expression command in the
;;; Lisp menu. Try evaluating the following expressions
;;; in the manner just described. The results from  each
;;; evaluation will appear in the Listener window.


;;; To evaluate a list double-click one of the outer
;;; parentheses to select the whole expression. Then
;;; use Eval Selection to evaluate it.
;;; You can also evaluate expressions by placing the
;;; cursor on the start or just after the expression 
;;; and then typing: C-x C-e (control-x control-e).

(* 2 pi )
(list 2 pi)
(sin (* 2 pi ))
(define albans-row '(0 3 7 11 2 5 9 1 4 6 8 10))
(define (row->matrix row)
  ;; this function is discussed in Chapter 8
  (loop for i in row
        (loop for j in row
              collect (mod (+ (- i) j) 12))))
(pprint (row->matrix albans-row))

Chapter Source Code

The source code to all of the examples and interactions in this chapter can be found in the file cmapp.cm located in the same directory as the HTML file for this chapter. The source file can be edited in a text editor or evaluated inside the Common Music application.