Messiaen Quartet for the end of time And another.

Slides:



Advertisements
Similar presentations
Arrays A list is an ordered collection of scalars. An array is a variable that holds a list. Arrays have a minimum size of 0 and a very large maximum size.
Advertisements

CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
 After the 7 transactions, the ledger looks like Page 105 Figure 4.5. (Show On the White board)  There are 10 accounts in the ledger.  How do you calculate.
331 Final Fall Details 3:30-5:30 Monday, December 16 ITE 229 (this room!) Comprehensive with more emphasis on material since the midterm Look at.
Recursion Great fleas have little fleas upon their backs to bite 'em, And little fleas have lesser fleas, and so ad infinitum. And the great fleas themselves,
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
ITERATIVE CONSTRUCTS: DOLIST Dolist is an iterative construct (a loop statement) consisting of a variable declaration and a body The body states what happens.
Lisp. Versions of LISP Lisp is an old language with many variants –LISP is an acronym for List Processing language Lisp is alive and well today Most modern.
Recursion.
CS 201 Functions Debzani Deb.
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
Functional Programming COMP2003 A course on functional programming using Common Lisp Dr Eleni Mangina
Simplifying Rational Expressions – Part I
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
Encoding, Validation and Verification Chapter 1. Introduction This presentation covers the following: – Data encoding – Data validation – Data verification.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
331 Final Spring Details 6-8 pm next Monday Comprehensive with more emphasis on material since the midterm Study example finals and midterm exams.
Recursion, Complexity, and Sorting By Andrew Zeng.
Python Programming Chapter 6: Iteration Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
Recursion Recursion Chapter 12. Outline n What is recursion n Recursive algorithms with simple variables n Recursion and the run-time stack n Recursion.
Moving Around in Scratch The Basics… -You do want to have Scratch open as you will be creating a program. -Follow the instructions and if you have questions.
Function Design in LISP. Program Files n LISP programs are plain text –DOS extensions vary; use.lsp for this course n (load “filename.lsp”) n Can use.
Machaut Messe Performance Performance Performance Isorhythm Isorhythm.
Recursive Data Structures and Grammars  Themes  Recursive Description of Data Structures  Recursive Definitions of Properties of Data Structures  Recursive.
1 CS161 Introduction to Computer Science Topic #9.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
By Edward Lim 8.7. What? Today, we continued our research on our chosen Cornerstone Piece, we got our learning journals up to date, we made sure all our.
BIT116: Scripting Associative Arrays. Today AngularJS Q + A for the exam 2.
Introduction to LISP Atoms, Lists Math. LISP n LISt Processing n Function model –Program = function definition –Give arguments –Returns values n Mathematical.
Project. Research Project Due: – Project report due Monday midnight Delayed a bit due to popular demand Can accept an even higher delay (Tuesday at noon)
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
CS12230 Introduction to Programming Lecture 6-2 –Errors and Exceptions 1.
Memory Management OS Fazal Rehman Shamil. swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
RetrogradeRetrograde. Divide and Conquer Concept first Data: ‘(( )( )) We want this to look like ‘(( )(500.
1 Recursion Recursive function: a function that calls itself (directly or indirectly). Recursion is often a good alternative to iteration (loops). Its.
Detailing your features for your second client meeting What to put on your Google Group for them to review!
Introduction to Exceptions in Java CS201, SW Development Methods.
CSE 351 Caches. Before we start… A lot of people confused lea and mov on the midterm Totally understandable, but it’s important to make the distinction.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Artificial Intelligence and Lisp Lecture 6 LiU Course TDDC65 Autumn Semester,
Memory Management.
Component 1.6.
User-Written Functions
Questions?.
Lesson One – Creating a thread
What to do when a test fails
Data Structures Interview / VIVA Questions and Answers
Error Handling Summary of the next few pages: Error Handling Cursors.
Recursion Great fleas have little fleas upon their backs to bite 'em, And little fleas have lesser fleas, and so ad infinitum. And the great fleas themselves,
More Selections BIS1523 – Lecture 9.
Conditions and Ifs BIS1523 – Lecture 8.
The Metacircular Evaluator
Introduction When searching for a new mattress, you have to make sure you know where to go to find the best one. The mattress you sleep on is going to.
Delayed Evaluation Special forms in Scheme (e.g., if and cond) do not use applicative order evaluation Only one of two or more expressions is actually.
Recursion Great fleas have little fleas upon their backs to bite 'em, And little fleas have lesser fleas, and so ad infinitum. And the great fleas themselves,
Yan Shi CS/SE 2630 Lecture Notes
Java Programming Language
Software Development Techniques
Lecture 20 – Practice Exercises 4
Presentation transcript:

Messiaen Quartet for the end of time And another

Now for the fun (hard) part Recursion Necessary to work on LISTS of data where we want to affect each element of the list as in (add-one ( )) ( )

Recursion Lisp is widely known for its use of recursion, functions that call themselves during execution with lesser and lesser elements of their arbitrary-length list arguments. Using recursion therefore means that users need not know the actual length of list arguments in order to access them, a great advantage when manipulating vast amounts of information.

The following code describes a user- defined recursive function also called add-one that adds 1 to each of the elements in its list argument. (defun add-one (list-of-numbers) (if (null list-of-numbers) () (cons (+ 1 (first list-of-numbers)) (add-one (rest list-of-numbers)))))

How it works: (line 1) the first line of code names the function and declares the variables that will represent its argument(s) in a list (in this case only one named argument exists). (defun add-one (list-of-numbers)

Continue (line 2) the function if in this case tests the argument list-of-numbers to ascertain if it contains data, and if empty it then returns an empty list (second line of code) (if (null list-of-numbers) ()

Continue (line 3) if (else) the list still contains entries, the code constructs a list consisting of 1 added to the first of add- one's list argument (cons (+ 1 (first list-of-numbers))

Continue (line 4) the result of add-one's application to the remainder of the list. (add-one (rest list-of-numbers)))))

Here we go again: (defun add-one (list-of-numbers) (if (null list-of-numbers) () (cons (+ 1 (first list-of-numbers)) (add-one (rest list-of-numbers)))))

Note The terminating code (or second line) in the definition of add-one must occur first, because if the function add-one were to attempt to add 1 to an empty list, it would fail (since (), read also as nil, is not a number in its final recursive call).

Note The terminating code (or second line) in the definition of add-one must occur first, because if the function add-one were to attempt to add 1 to an empty list, it would fail (since (), read also as nil, is not a number in its final recursive call).

What really happens (cons (+ 1 1 ) (cons (+ 1 2 ) (cons (+ 1 3) ()))) Where the last empty parentheses acts as the empty list in which all the remainder of the numbers are placed.

Again Lets try it all over again

Recursion The ability of a function to call itself on lesser and lesser amounts of its argument until the argument is empty.

Begin (defun add-one (list-of-numbers) Looks pretty much like before, but remember that the variable list-of-numbers is going to be a list that we will want to add one to each of its elements.

Hard part We know that if we call the function over and over again it will finally find an empty list and if we try to add 1 to nil well get an error. Thus the first thing we want to do is to make sure we have a default way to escape the recursion.

(defun add-one (list-of-numbers) (if (null list-of-numbers) nil What this does is if the list is empty, then we want it to return nil or an empty list. This will become clear when we finish the function.

Heres where cons comes in handy (defun add-one (list-of-numbers) (if (null list-of-numbers) () (cons (+ 1 (first list-of-numbers)) We collect the first of the list altered by adding one to it.

And now (defun add-one (list-of-numbers) (if (null list-of-numbers) () (cons (+ 1 (first list-of-numbers)) (add-one (rest list-of-numbers))))) Were done and time to review the process. Especially the last line where the recursion is.

Recursion (defun add-one (list-of-numbers) ;;;name the fcn and arg (if (null list-of-numbers) () ;;;ensure no mistake (cons (+ 1 (first list-of-numbers)) ;;;cons add (add-one (rest list-of-numbers))))) ;;;recurse Note how each time the function recurses, it does so without its first element. Slowly this moves down the list until its nil when the conditional if saves us from adding a number (1) to a nil (error!!!!).

Pretend We have (add-one (1 2 3)) Then it works like this: (cons (+ 1 1 ) (cons (+ 1 2 ) (cons (+ 1 3) ()))) (defun add-one (list-of-numbers) ;;;name the fcn and arg (if (null list-of-numbers) () ;;;ensure no mistake (cons (+ 1 (first list-of-numbers)) ;;;cons add (add-one (rest list-of-numbers))))) ;;;recurse To give us (2 3 4) The empty list at the end of the above is in line 2 of the function definition.

Yet another way to look at it: Imagine a cylinder You grab a number from the list, add one to it, then Push it into the cylinder. Continue doing this until you reach an empty list. Then use the empty list and pull the added-numbers out one by one (backwards) and put them into the empty list (backwards) and you end up with the riginal list. The cylinder is called a stack in computerize.

Whew Basically we are done. There are a few things that we will need to learn (other primitive names, alternative ways to do things, save midi files, etc.) but this is pretty much it. On the other hand, you will have to REALLY get this in your blood. PRACTICE……

Assignment Write a normalization function. Normalization is bringing numbers within a particular range. For example, if we have a number that occurs in a range of we might want to make it a pitch (midi pitches for us will be 24 to 96). 500 in the first range would therefore be 60 in the second range. Now, what if we had a whole bunch of numbers in the range. We will need a function that will place all of these numbers in our midi range.

You will need two functions: 1) you will need a function that will normalize a single number; and then 2) youll need another function that will run the above function through the entire list of numbers. The result will be a new list of normalized and and thus playable midi notes. We will make music with this next Monday. Everyone will make a piece next week!!!!!

Remember to DIVIDE AND CONQUER No great math is needed, just patience and LOGIC.

I am at so if you really have problems, send me your code an d/or OR do you want to set up the chat list now?????????

Also, check out the new exercises on the class website.

Final projects One more week to figure these out?

Next week We will all create our own works in class and play them for one another!