====== CMPU-101 Lecture Notes ====== ===== Spring 2013 ===== === Lecture 22 === * May 1 and 2: {{courses:cs101-201301:lectures:lect22posted.txt|Lecture 22 notes (.txt)}}{{courses:cs101-201301:lectures:lect22posted.rkt|Lecture 22 notes (.rkt)}} \\ //Latest copies of lect22 notes were posted on 5/14/13 at 7:20 am// * Sorting - Insertion Sort - Merge Sort === Lecture 21 === * April 24,25,29 and 30: {{courses:cs101-201301:lectures:lect21posted.txt|Lecture 21 notes (.txt)}}{{courses:cs101-201301:lectures:lect21posted.rkt|Lecture 21 notes (.rkt)}} \\ //Latest copies of lect21 notes were posted on 5/14/13 at 7 am// * Another self-referential data type: Trees - binary trees - binary search trees * Inserting nodes into binary search trees * Using the binary search tree properties to potentially shorten search process. === Lecture 20 === * April 22 and 23: {{courses:cs101-201301:lectures:lect20.txt|Lecture 20 notes (.txt)}}{{courses:cs101-201301:lectures:lect20.rkt|Lecture 20 notes (.rkt)}} \\ //Latest copies of lect20 notes were posted on 4/25/13 at 1:33 pm// * String processing * Main approaches: - Using recursion on the position number to traverse a string. - Using explode on the string (making a list) and either using explicit list recursion or a higher-order function for lists. * Using the character data type - **string-ref** produces character at particular position in a string. - There are numerous character functions to use on the result of string-ref. - **string** consumes a number of characters and converts them into a single string. * Examples: - Writing a function to detect vowels - Writing a palindrome detector - Writing an interactive pig-latin translator * {{courses:cs101-201301:lectures:lect20posted.rkt|Solutions to lecture 20 (.rkt)}} \\ {{courses:cs101-201301:lectures:lect20posted.txt| Solutions to lecture 20 (.txt)}} === Lecture 19 === * April 17 and 18: {{courses:cs101-201301:lectures:lect19.txt|Lecture 19 notes (.txt)}}{{courses:cs101-201301:lectures:lect19.rkt|Lecture 19 notes (.rkt)}} \\ //Latest copies of lect19 were posted on 4/25/13 at 12:30 pm// * Writing animations with lists - modifying big-bang functions to process lists. * Adding a mouse handler to a simulation. * {{courses:cs101-201301:lectures:lect19posted.rkt|Solutions to lecture 19 (.rkt)}} \\ {{courses:cs101-201301:lectures:lect19posted.txt| Solutions to lecture 19 (.txt)}} === Lecture 18 === * April 15 and 16: {{courses:cs101-201301:lectures:lect18-52.txt|Lecture 18 notes (.txt)}}{{courses:cs101-201301:lectures:lect18-52.rkt|Lecture 18 notes (.rkt)}} \\ //Last updated on 4/17/13 at 8:50 am.// * Writing animations - **big bang** function - working with simulation started in homework 6 - using **on-key** clause to respond to key presses - using stop-when clause to end the simulation and to create a final scene * Mutation using set! * Look up **big-bang** in the help desk. Read section 2.4 of the help desk page that opens when you search for **big-bang** //Worlds and the Universe: "universe.ss"// up to and including sections 2.4.3. * Read Chapter 6 (pages 91-107) and chapter 18 (pages 247-254) in the book "Picturing Programs" (posted on the left side of this screen). They define functions without explicitly using lambda. Otherwise, the examples should be understandable. To run the examples, you should add the line **(require picturing-programs)** to the top of your code. === Lecture 17 === * April 10 and 11: {{courses:cs101-201301:lectures:lect17post.txt|Worked Lecture 17 notes (.txt)}}{{courses:cs101-201301:lectures:lect17post.rkt|Worked Lecture 17 notes (.rkt)}} * Writing functions that process and produce lists of posns. * Writing animations - **big bang** function * Look up **big-bang** in the help desk. Read section 2.4 of the help desk page that opens when you search for **big-bang** //Worlds and the Universe: "universe.ss"// up to and including sections 2.4.3. * Read Chapter 6 (pages 91-107) in the book "Picturing Programs" (posted on the left side of this screen). They define functions without explicitly using lambda. Otherwise, the examples should be understandable. To run the examples, you should add the line **(require picturing-programs)** to the top of your code. === Lecture 16 === * April 8 and 9: {{courses:cs101-201301:lectures:lect16post.txt|Worked Lecture 16 notes (.txt)}}{{courses:cs101-201301:lectures:lect16post.rkt|Worked Lecture 16 notes (.rkt)}} (posted on 4/11/13 at 8:02 pm) * Review writing animations - **animate** function: This function has been replaced and made obsolete by the big-bang simulation code. - **big bang** function * on-draw, on-tick, and stop-when clauses * Several improvements to rocket landing scene. * {{http://www.ccs.neu.edu/home/matthias/HtDP2e/part_prologue.html#%28part._pro-cond%29|Sections 1.3-1.7 of HtDP 2nd edition}}. {{http://www.ccs.neu.edu/home/matthias/HtDP2e/part_one.html#%28part._ch~3astructure%29|Section 2.5 through 2.7 of HtDP 2nd edition}}. When looking at the examples in this book, remember that they define functions without explicitly using lambda. Otherwise the examples should be understandable. * Look up **big-bang** in the help desk. Read section 2.4 of the help desk page that opens when you search for **big-bang** //Worlds and the Universe: "universe.ss"// up to and including sections 2.4.3. * Read Chapter 6 (pages 91-107) in the book "Picturing Programs" (posted on the left side of this screen). They define functions without explicitly using lambda. Otherwise, the examples should be understandable. To run the examples, you should add the line **(require picturing-programs)** to the top of your code. === Lecture 15 === * April 3 and 4: {{courses:cs101-201301:lectures:lect15post.txt|Worked Lecture 15 (.txt)}} {{courses:cs101-201301:lectures:lect15post.rkt|Worked Lecture 15 (.rkt)}} (posted at 6:05 pm on 4/6/13) /* * {{courses:cs101-201301:lectures:lect13post.txt|Worked lecture notes (.txt)}}{{courses:cs101-201301:lectures:lect13post.rkt|Worked lecture notes (.rkt)}} * {{courses:cs101-201301:lectures:lect12post.rkt|Worked lecture notes (.rkt)}} {{courses:cs101-201301:lectures:lect12post.txt|Worked lecture notes (.txt)}} */ * Writing animations - **animate** function - **big bang** function * on-draw, on-tick, and stop-when clauses * {{http://www.ccs.neu.edu/home/matthias/HtDP2e/part_prologue.html#%28part._pro-cond%29|Sections 1.3-1.7 of HtDP 2nd edition}}. When looking at the examples in this book, remember that they define functions without explicitly using lambda. Otherwise the examples should be understandable. * Look up **big-bang** in the help desk. Read section 2.4 of the help desk page that opens when you search for **big-bang** //Worlds and the Universe: "universe.ss"// up to and including sections 2.4.3. === Lecture 14 === * April 1 and 2: {{courses:cs101-201301:lectures:lect14.txt|Lecture 14 (.txt)}} {{courses:cs101-201301:lectures:lect14.rkt|Lecture 14 (.rkt)}} * {{courses:cs101-201301:lectures:lect14post.txt|Worked lecture notes (.txt)}}{{courses:cs101-201301:lectures:lect14post.rkt|Worked lecture notes (.rkt)}} /* * {{courses:cs101-201301:lectures:lect12post.rkt|Worked lecture notes (.rkt)}} {{courses:cs101-201301:lectures:lect12post.txt|Worked lecture notes (.txt)}} */ * Containers for finite amounts of data: **struct**s * Built-in **posn** and **color** structs * Creating new types using **define-struct** - Functions created by define-struct: constructor, accessors, mutators, type-checker * {{http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-9.html#node_sec_6.1|Sections 6.1 and 6.3 in HtDP 1st edition}}. When looking at the examples in this book, remember that they define functions without explicitly using lambda. Otherwise the examples should be understandable. === Lecture 13 === * Mar 27 & 28: {{courses:cs101-201301:lectures:lect13.txt|Lecture 13 (.txt)}} {{courses:cs101-201301:lectures:lect13.rkt|Lecture 13 (.rkt)}} * {{courses:cs101-201301:lectures:lect13post.txt|Worked lecture notes (.txt)}}{{courses:cs101-201301:lectures:lect13post.rkt|Worked lecture notes (.rkt)}} /* * {{courses:cs101-201301:lectures:lect12post.rkt|Worked lecture notes (.rkt)}} {{courses:cs101-201301:lectures:lect12post.txt|Worked lecture notes (.txt)}} */ * Reading input from the keyboard * Using the **read** function. * Using a **let** expression as a slightly abbreviated form of **local** (information on the **let** expression can be found on pages 62-65 of Part 4 of our pdf notes, included with lecture 6). * Creating interactive programs involving random events and input from keyboard. * Reading assignment: *{{courses:cs101-201301:lectures:part6.pdf|Part 6 of pdf lecture notes, pages 83-84}} === Lecture 12 === * Mar 25 & 26: {{courses:cs101-201301:lectures:lect12.txt|Lecture 12 (.txt)}} {{courses:cs101-201301:lectures:lect12.rkt|Lecture 12 (.rkt)}} * {{courses:cs101-201301:lectures:lect12post.rkt|Worked lecture notes (.rkt)}} {{courses:cs101-201301:lectures:lect12post.txt|Worked lecture notes (.txt)}} * Generating random numbers (see pages 77-78 of Part 5 of the pdf lecture notes, posted with lecture 9) * Using the **random** function to add uncertainty to programs and to create lists of random values. * Higher-order functions: **filter**, **map**, **apply**, and **build-list**. * Reading assignment: *{{courses:cs101-201301:lectures:part6.pdf|Part 6 of pdf lecture notes, pages 79-82}} * {{http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-27.html#node_chap_21|Sections 21.1 and 21.2 in HtDP 1st edition}}. When looking at the examples in this book, remember that they define functions without explicitly using lambda. Otherwise the examples should be understandable. === Lecture 11 === * Mar 4 & 5: {{courses:cs101-201301:lectures:lect11.txt|Lecture 11 (.txt)}} {{courses:cs101-201301:lectures:lect11.rkt|Lecture 11 (.rkt)}} These are the solution files. * Built-in functions for flat lists: **append**, **list-ref**, **reverse**, **length**, **list**, and **member?**. * Writing functions that produce lists. /* * Generating random numbers (see pages 77-78 of Part 5 of our pdf lecture notes) - Using the **random** function to add uncertainty to our programs. * **Structs** - [[http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-9.html#node_sec_6.1|How to Design Programs, 1st edition, section 6.1]] Skip section 6.2 and [[http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-9.html#node_sec_6.3|read sections 6.3 and 6.4]] - [[http://www.ccs.neu.edu/home/matthias/HtDP2e/part_one.html#(part._ch~3astructure)|How to Design Programs, 2nd edition, section 2.5 (only up to, but not including 2.5.2)]] \\ * Built-in Structs: - **posn** * {{courses:cs101-201301:lectures:lect9post.rkt|Solutions to lecture 9 (.rkt)}} \\ {{courses:cs101-201301:lectures:lect9post.txt| Solutions to lecture 9 (.txt)}} */ === Lecture 10 === * Feb 27 & 28: {{courses:cs101-201301:lectures:lect10-51.txt|Lecture 10 (.txt)}} {{courses:cs101-201301:lectures:lect10-51.rkt|Lecture 10 (.rkt)}} * Read pages 68-71 of pdf lecture notes, Part 4. * Abbreviated list constructors. - **list** function - **'** before open parenthesis of list * Writing functions that consume and produce lists. * Writing functions that consume lists of images and put them all on a scene. - **place-image** function - representation of x-y plane when using Racket graphics * {{courses:cs101-201301:lectures:lect10post.rkt|Solutions to lecture 10 (.rkt)}} \\ {{courses:cs101-201301:lectures:lect10post.txt| Solutions to lecture 10 (.txt)}} === Lecture 9 === * Feb 25 & 26: {{courses:cs101-201301:lectures:lect9.txt|Lecture 9 (.txt)}} {{courses:cs101-201301:lectures:lect9.rkt|Lecture 9 (.rkt)}} * Lists - a self-referential data type - **cons**: list constructor function; adds one element at a time - **first**: function that returns left-most element from list - **rest**: function that returns list containing all but left-most element - **list**: list constructor function, creates a list consisting of all its arguments * Reading assignment: - {{courses:cs101-201301:lectures:part5.pdf|Part 5, pages 72 - 78}} - [[http://www.ccs.neu.edu/home/matthias/HtDP2e/part_two.html|How to Design Programs, 2nd edition, section 4.1]] \\ NOTE: This book uses a different notation to define functions. See the top of the class notes for a description of this notation. * {{courses:cs101-201301:lectures:lect9post.rkt|Solutions to lecture 9 (.rkt)}} \\ {{courses:cs101-201301:lectures:lect9post.txt| Solutions to lecture 9 (.txt)}} === Lecture 8 === * Feb 18 through 20: {{courses:cs101-201301:lectures:lect8.txt|Lecture 8 (.txt)}} {{courses:cs101-201301:lectures:lect8.rkt|Lecture 8 (.rkt)}} * Reading assignment: posted with lecture 6, pages 65-71. * Writing regular recursive, tail-recursive (accumulator), and wrapper function using equation to approximate pi. * Local: - used to define constants and functions inside functions. * {{courses:cs101-201301:lectures:lect8post.rkt|Solutions to lecture 8 (.rkt)}} \\ {{courses:cs101-201301:lectures:lect8post.txt| Solutions to lecture 8 (.txt)}} === Lecture 7 === * Feb 13 & 14: {{courses:cs101-201301:lectures:lect7.txt|Lecture 7 (.txt)}} {{courses:cs101-201301:lectures:lect7.rkt|Lecture 7 (.rkt)}} * Reading assignment: posted with lecture 6, pages 59-61. * Accumulator Functions: - tail recursion - extra accumulator parameter - wrapper functions - **local** special form * {{courses:cs101-201301:lectures:lect7post.rkt|Solutions to lecture 7 (.rkt)}} \\ {{courses:cs101-201301:lectures:lect7post.txt| Solutions to lecture 7 (.txt)}} === Lecture 6 === * Feb 11 & 12: {{courses:cs101-201301:lectures:lect6.txt|Lecture 6 (.txt)}} {{courses:cs101-201301:lectures:lect6.rkt|Lecture 6 (.rkt)}} * Reading assignment: {{courses:cs101-201301:lectures:part4.pdf|Part 4}}, pages 53-71. * **require**: Special form to include libraries. * Recursive Functions: - **numeric recursion** * base case(s). * recursive case(s). * factorial function: Several versions are shown. * local environments created in calls to recursive functions. * {{courses:cs101-201301:lectures:lect6post.rkt|Solutions to lecture 6 (.rkt)}} \\ {{courses:cs101-201301:lectures:lect6post.txt| Solutions to lecture 6 (.txt)}} === Lecture 5 === * Feb 6 & 7: {{courses:cs101-201301:lectures:lect5.txt|Lecture 5 (.txt)}} {{courses:cs101-201301:lectures:lect5.rkt|Lecture 5 (.rkt)}} * Reading assignment: Part 3 (see notes posted with lecture 4), pages 42-47 * Defining names for values (constants) in the global environment. * Decision special forms: - **if** * Decision statement designed for two-choice decisions. - **cond** * Decision statement designed for multiple-choice decisions. * {{courses:cs101-201301:lectures:lect5post.rkt|Lecture notes with solutions (.rkt)}} \\ {{courses:cs101-201301:lectures:lect5post.txt|Lecture notes with solutions (.txt)}} === Lecture 4 === * Feb 4 & 5: {{courses:cs101-201301:lectures:lect4.txt|Lecture 4 (.txt)}} {{courses:cs101-201301:lectures:lect4.rkt|Lecture 4 (.rkt)}} * Reading assignment: - {{courses:cs101-201301:lectures:part3.pdf|Part 3, pages 40-52}} * The BEGIN special form. * The design recipe for function definitions. - Contract - Header - Purpose - Automatic function testing * CHECK-EXPECT and CHECK-WITHIN special forms - Post-function printf's * Predicate functions * Logical "operators": - AND and OR special forms - NOT function * {{courses:cs101-201301:lectures:lect4-post.rkt| Lecture notes with solutions (.rkt)}} * {{courses:cs101-201301:lectures:lect4-post.txt| Lecture notes with solutions (.txt)}} === Lecture 3 === * Jan 30 & 31: {{courses:cs101-201301:lectures:lect3.txt|Lecture 3 (.txt)}} {{courses:cs101-201301:lectures:lect3.rkt|Lecture 3 (.rkt)}} * Reading assignments: - {{courses:cs101-201301:lectures:part2.pdf|Part 2, pages 22-40}} * The DEFINE special form. - Evaluation of a define expression. - Adding names and constant values to the global environment. - Adding names and function definitions to the global environment. * The LAMBDA special form. - Evaluation of a lambda special form. - Parts of a lambda special form. - Calling an unnamed lambda expression with input arguments. - Practice writing unnamed lambda expressions. * Combining define and lambda special forms to name functions in the global environment. * {{courses:cs101-201301:lectures:lect3sol.rkt|Solutions to problems in lect3 (lect3sol.rkt)}} \\ {{courses:cs101-201301:lectures:lect3sol.txt|Solutions to problems in lect3 (lect3sol.txt)}} === Lecture 2 === * Jan 28 & 29: {{courses:cs101-201301:lectures:lect2.txt|Lecture 2 (.txt)}} {{courses:cs101-201301:lectures:lect2.rkt|Lecture 2 (.rkt)}} * Reading assignments: - {{courses:cs101-201301:lectures:part1.pdf|Part 1, pages 1-21}} - {{courses:cs101-201301:lectures:part2.pdf|Part 2, pages 22-40}} * Looking up library function names. * Reading library function contracts. * Default evaluation and pattern of primitive function calls. * Prefix notation. Converting infix to prefix notation. * Evaluation of nested function calls. * DISPLAY, PRINTF, and NEWLINE functions. === Lecture 1 === * Jan 23 & 24: {{courses:cs101-201301:lectures:lect1.txt|Lecture 1 (.txt)}} {{courses:cs101-201301:lectures:lect1.rkt|Lecture 1 (.rkt)}} - Review of on-line syllabus. - Reading assignment: {{courses:cs101-201301:lectures:part1.pdf|Part 1, pages 1-21}} - Introduction to Racket * Syntax vs Semantics * Functional languages: function evaluation central part of computational model. - Programming entities (i.e., data types) and keywords (special forms). - Evaluation of primitive and compound data types. - Introduction to Global Environment (GE). - Default evaluation of non-empty, non-quoted lists. - Software you will need and how to download it * DrRacket: an Integrated Development Environment. - File extensions and their meaning. - Introduction to CS accounts in Lab 1 on Jan 25th and 29th.