490 likes | 668 Views
Machaut Messe. Performance Isorhythm. Review. Remember. All Lisp expressions must have matched parentheses; that is, every open paren must appropriately have a closed paren.
E N D
Machaut Messe • Performance • Isorhythm
Remember • All Lisp expressions must have matched parentheses; that is, every open paren must appropriately have a closed paren. • Document all of your work by placing comments after a “;” or enclosing in “”, or placing between #| this is documentation |# • Name variables and everything you do such that later on you can tell what they mean and does.
Remember • Readability is @#$%^&* everything
Hummmmmmm • (+ (first *my-numbers*) (third *my-numbers*) (first *my-numbers*)) Note how much easier the above is to read than: • (+ (first *my-numbers*)(third *my-numbers*)(first *my-numbers*)) • 4
More exercises • (nth 5 ‘(1 2 3 4 5 6)) • 6 • Remember to check whether the primitive you’re using is zero or one based as in • (nthcdr 5 ‘(1 2 3 4 5 6)) • 6 • whew
More? • (position 1 '(2 1 3 4 5)) • 1 (position 2 '(2 1 3 4 5)) 0 And so on.
From (0 60 1000 1 64) get: • 1) 0 • 2) 64 • 3) 1000 • 4) (1000 1 64) • 5) (60 1000) • 6) (0 60 1000) • 7) (0 1) • 8) ((0)) • 9) (60 1000 64) • 10) (60 0)
From (((a) b) c) get: • 1) a • 2) c • 3) b • 4) (a b) • 5) (a (b c)))
From (a b c d e) get: • 1) (d e) • 2) 5 • 3) (a (b (c (d (e))))) • 4) (e d c b a) • 5) (a b c d)
From a get: • 1) (a) • 2) (a . a) • 3) (a (a)) • 4) ((a) a) • 5) (a ())
From a and (b c) get: • 1) (a b c) • 2) ((a) b c) • 3) (a (b c)) • 4) (a c) • 5) (c b a)
From (a b) and (c d) get: • 1) (a b c d) • 2) ((a b) c d) • 3) ((a b)(c d)) • 4) (b a d c) • 5) (a (b c) d)
Cope-event • (0 60 1000 1 127) • On-time (1000 per second) • Pitch number (24 108) • Duration (1000 per second) • Channel (1-16) • Loudness (1- 127)
Therefore • (0 60 1000 1 127) • Translates to • A loud quarter-note middle C on channel 1 • Channel assignments are separate and (except for channel 10 usually) can produce any general MIDI sound • When saved to MIDI file and opened in a notation program produces the above.
Cope-events • ((0 60 1000 1 127)(1000 62 1000 1 127)(2000 64 1000 1 127)(3000 65 1000 1 127)(4000 67 1000 1 127)(5000 69 1000 1 127)(6000 71 1000 1 127)(7000 72 1000 1 127)) • Produces a loud C-major scale in quarter notes.
Some more functions • + (can have any number of args) • - (can have any number of args) • / (can have any number of args) • * (can have any number of args) • sort (be careful) • exp • sqrt • sin, cosin, tan (etc.)
Predicates • Some Lisp functions serve as test functions as in • (listp 1) • which returns nil because its argument is not a list • (atomp ‘(1)) • which returns nil because its argument is not an atom • The suffix “p” stands for predicate
Conditionals • Some functions in Common Lisp—called conditionals—test data for certain attributes. • For example, the function if tests its first argument and returns its second argument if it proves true, or its third argument if it proves false.
Example • ? (if (numberp 1) t nil) • Returns • T • because “1” is a number and thus the first choice (t) is the result • Note that Lisp is case insensitive.
Named • This combination is often termed an if-then-else clause.
Quiz • ? (if (numberp (second ‘(a 2 b d f)) ‘yes ‘no) returns • > yes
Quiz • ? (cons 1 (rest ‘(1 2 3 4 5))) returns > (1 2 3 4 5) Whew.
Let’s try for a few combinations • (defvar *my-numbers* ‘(1 2 3)) • (if (equal (first *my-numbers*) 2) (third *my-numbers*) (first *my-numbers*)) What’s the answer?
Answer • 1
Another • (append (append *my-numbers* *my-numbers*) (rest *my-numbers*))
Answer • (1 2 3 1 2 3 2 3)
A little harder • (if *my-numbers* (last *my-numbers*) ())
Answer • (3) • N.B. The function “last” returns a list of the last number. Weird, but true.
Try this: • (if (equal *my-numbers* (1 2 3)) (reverse *my-numbers*))
Answer • Error! (forget the single quote on data!!!)
Whew! • (third ‘((((a)) b)(c ((d) e) f)(((g)) h I))
Answer • (((g)) h I))