Structure and Interpretation of Music Concepts Chapter 2 -- Music Primitives Homework no. 1 Due: Nov. 7th, 2002 This homework assignment is your first "meeting" with Scheme. You can consult with the notes of class1-scheme.txt. The book is always a great source. The POP notes follow the book chapters (found in the bib link in the course site). 1. Define a procedure named 'square-dif-pitch' that takes 3 numbers as arguments and returns a note whose pitch, duration, and loudness values are the square of the difference of the 2 smaller numbers. 2. Given the following two procedures: (define (increase-pitch pitch) (increase-pitch (make-pitch (add1 (pitch-class pitch)) (pitch-octave pitch)))) (define (test-pitch p q) (if (= (midi-pitch p) 60) 0 q)) What is the result of evaluating the form (test-pitch (make-pitch 0 4) (increase-pitch (make-pitch 5 3))) under applicative-order evaluation and under normal-order evaluation? 3. Suggest an appropriate note-value for a rest. Note that it must have a duration property. 4. The pitch linear upward curve given in class results a simultaneous play for all notes. In order to repair the problem we need to enable some delayed play. a. Write a procedure for delayed play of a note. b. The delayed play can be used within two different accounts for the machine clock: 1. The machine clock, sampled by applying > (midi-get-time) 2233299029 is computed prior to every play -- and the delayed play is computed relative to it. 2. The machine clock is sampled only once -- in the beginning, and the desired delayes are accumulated relative to it. Write two different procedures that demonstrate the two approaches. Discuss and demonstrate the advantages/drawbacks of each. If you need a time-consuming procedure, you can use the recursive Fibonacci procedure defined in SICP (1.2 -- see also POP notes, class2). Always, take care to use the embedded procedures style of writing, taking advantage of lexical scoping to remove unnecessary parameters from the embedded procedures. 5. Suppose that we replace the primitive procedure "if" by a compound procedure "new-if", defined using "cond" as follows: (define (new-if predicate then-clause else-clause) (cond (predicate then-clause) (else else-clause))) For example: (new-if (= 5 5) 0 1) evaluates to 0, and (new-if (= 5 6) 0 1) evaluates to 1. Try it! Consider the following procedure for computing the factorial function: (define (factorial n) (new-if (= n 1) 1 (* n (factorial (- n 1) ) ) )) Try this definition of factorial. Explain what happens.