CS3 Fall 2005 Lecture 10: More on higher order functions.

Slides:



Advertisements
Similar presentations
BIOLOGY Homework: Cells Unit Chapter 7
Advertisements

CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 17: HOF and Tick-Tack-Toe.
CS3 Fall 2005 Lecture 11: Finish higher order functions Midterm Prep.
Slide 1 CS3: Lecture 8 Advanced recursion. Slide 2 Schedule Oct 10Advanced recursion Oct 17Number-spelling Miniproject Oct 24Higher order procedures Oct.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 18: HOF.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 14: Number Spelling Mini-project.
Slide 1 CS3 Week 8: Recursion. Slide 2 Midterm 1 You did great If you need a re- grade, see the person that graded that question Solutions are available.
Slide 1. Slide 2 Administrivia Mid-semester survey this week (Thur/Fri) –you NEED to do this. Interviews should be starting in a few weeks. I apologize.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 12: Homework stuff and Accumulating Recursion.
6.001 SICP SICP – September Processes, Substitution, Recusion, and Iteration Trevor Darrell 32-D web page:
Slide 1 CS3 Fall 2005 Lecture week 13: Introduction to the Big Project.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 19: HOF Problems.
CS3: Introduction to Symbolic Programming Spring 2006Nate Titterton Lecture 4: "Difference Between Dates" and data abstraction.
Slide 1 Midterm 1 Midterm 1: Feb 28 th (next week). –In the lecture slot, plus 20 minutes (4:10-5:30 pm, 120 Latimer) –Everything we’ve covered, including.
Monday, 12/9/02, Slide #1 CS 106 Intro to CS 1 Monday, 12/9/02  QUESTIONS??  On HW #5 (Due 5 pm today)  Today:  Recursive functions  Reading: Chapter.
Data Abstraction… The truth comes out…. What we’re doing today… Abstraction ADT: Dotted Pair ADT: List Box and Pointer List Recursion Deep List Recursion.
Slide 1. Slide 2 Midterm 1 You did great If you need a regrade, see the person that graded that question Solutions available on the portal soon.
CS 330 Programming Languages 11 / 18 / 2008 Instructor: Michael Eckmann.
Administrivia Make sure you have completed the Mid Semester Survey –Scheduled the week before Spring Break –this will be worth some points Reading is.
CS 280 Data Structures Professor John Peterson. Goals Understand “Programming in the small” Java programming Know what’s under the hood in complex libraries.
Feb 28More complicated recursions March 7Tree recursion, etc. Number-spelling Miniproject (#2) March 14Higher order procedures March 21Spring Break March.
CS3: Introduction to Symbolic Programming Spring 2006Nate Titterton Lecture 2: Introduction, and Conditionals.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 8: Recursion.
Midterm Logistics Where? 4 Leconte ( When? Monday, 4:10 to 5:40 What to do? –“Review problems”
Welcome to MAT 142. Basic Course Information Instructor Office Office Hours Beth Jones PSA 725 Tuesday 10 am – 10:45 am Wednesday 8:15 am – 9:15 am Thursday.
Administrative Issues ICS 151 Fall 2007 Instructor: Eli Bozorgzadeh.
Midterm Logistics Where? 2050 VLSB When? Monday, 4:10 to 5:40 What to do? –“Review problems” from Thursday/Friday in UCWise. –Two practice exams and solutions.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 16: Let and Lambda.
Slide 1 CS3 Fall 2005 Lecture 9: Higher Order Functions.
Information About Final Examination Economics 3479W Spring 2009.
CS3 Fall 2005 Lecture week 15. Administrivia The final survey will be up tomorrow: –you NEED to do this to receive a grade on your project! Final: –Saturday,
Administrivia Interviews this week: ex-TA Paul Hale Nate's office hours, as usual: Wed 2-4 The final survey will be up by Thursday: –you NEED to do this,
GEOMETRY – WEEK 1 (JAN. 6 TH – 10 TH ) Monday – Non-Student Day Tuesday – Introduction; Review for Ch. 6, 1-15 Wednesday – Warm-up 1-5; Notes, Section.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 15: Procedures as Arguments.
Slide 1. Slide 2 Administrivia Nate's office hours are Wed, 2-4, in 329 Soda! TA Clint will be handing out a paper survey in class sometime this week.
ALGEBRA II – Week 1 ( Jan. 6 th – 10 th )  Monday – Non-student Day  Tuesday – Overview; Note sheet 1-17  Wednesday – Warm-up 1-4; Notes, Section 7-1;
Please open your laptops and pull up Quiz Only the provided online calculator may be used on this quiz. You may use your yellow formula sheet for.
Calculus I – Course Syllabus Class Periods: 10:00am-10:50am MTWF Classroom: Thompson Hall 303 Instructor: Mei Q. Chen, Thompson Hall 328
CHEMISTRY 10123/10125 Spring 2007 Instructor: Professor Tracy Hanna Phone: Office: SWR 418
Calculus I – Course Syllabus Class Periods: 10:00am-10:50am MTWF Classroom: Thompson Hall 303 Instructor: Mei Q. Chen, Thompson Hall 328
YEAR 11 – EXAM PERIOD Monday 8 th June - Friday 12 th June WEEK 5.
August 27-31, Lab Time: Have a seat at your tables. Greens, get out the paper. Reds, get the necessary materials.
Week 6 - Wednesday.  What did we talk about last time?  Exam 1 post-mortem  Recursive running time.
PART OF SPEECH DEFINITION SYNONYM SENTENCE WORD ORIGIN NAME TEACHER AND DATE1 WORDS OF THE WEEK.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
Algebra II – Week 1 (Jan. 5 th – 9 th ) Monday – Introduction; Textbook, Pgs , 5-43 odd Tuesday – Warm-up; 1-4; Notes, Section 6; Workbook, Pg.
CS 123 Lab 4 Instructor: Mark Boady Course Designer: Professor Bruce Char Department of Computer Science Drexel University Spring 2013.
Where do we go from here? World Cultures Page Home.
Mr. Aldous’ Social Studies Literacy Class Plan Week of 9/14 – 9/18 AND 9/28 after Fall Break.
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Time Management Eric W. Ford, PhD 1/22/02. Plan a schedule of balanced activities.  College life has many aspects that are very important to success.
1/33 Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Tuesday December 4th 1. Review Game 2. Open Fall of the Roman Empire letter project Take notes from video 3. Fall of Roman Empire Video (40)
CS 330 Programming Languages 11 / 28 / 2006 Instructor: Michael Eckmann.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
CS 152: Programming Language Paradigms April 7 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak
CS61A Lecture Colleen Lewis. Clicker Test Are you coming to the potluck on Thursday on the 4 th floor of Soda from 6:30pm-9:00? A)Yes B)Maybe.
Monday – Brain on Fire reading quiz; view JBT ‘Stroke of Insight’ TED talk & prep for Socratic circle. Tuesday – Brain on Fire Socratic Discussion Wednesday.
CS3: Introduction to Symbolic Programming Spring 2006Nate Titterton Lecture 2: Introduction, and Conditionals.
CSE 3302 Programming Languages Chengkai Li Spring 2008 Functional Programming Language: Haskell (cont’d) Lecture 20 – Functional Programming, Spring 2008.
PART OF SPEECH DEFINITION SYNONYM SENTENCE NAME TEACHER AND DATE1 WORDS OF THE WEEK.
PART OF SPEECH DEFINITION SYNONYM SENTENCE NAME TEACHER AND DATE1 WORDS OF THE WEEK.
Organic Chemistry Lab 315 Fall, DUE DATES Today –At beginning of lab – Organic Qualitative Analysis and ID of Unknown.
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
COSC 5V90 Functional Programming and Interactive Theorem Proving
Lecture 4: Evaluation Rules Recursion CS200: Computer Science
Lecture 3: Rules of Evaluation CS200: Computer Science
Introduction to the Lab
GC16/3011 Functional Programming Lecture 9 Higher Order Functions
Organic Chemistry Lab 315 Fall, 2016
Presentation transcript:

CS3 Fall 2005 Lecture 10: More on higher order functions

Oct 24Higher order procedures Oct 31More HOF – "tic-tac-toe" program: SS chapter 10! – "Change Making" case study, in the reader Nov 7Miniproject #3: Election-processing – Friday is a holiday – Thursday a catch-up day – MP#3 due Thur/Fri: plan ahead! Review Session: Wednesday Nov 14Midterm #2 Lists Nov 21Start on the project: check-off #1 Nov 28Work on the project: checks #2 Dec 5Checkoff #3, finish the project Dec 17Final Exam (midterm #3)

Administrivia Reading is important for this week: –Tic-tac-toe, chapter 10 in Simply Scheme (Tuesday) –Difference between dates part III case-study in the reader (Tuesday) –Change-making case-study in the reader (Thursday) Note: there is a limit to the number of quizzes you can take outside of lab: 4 quizzes Make sure you have completed the Mid Semester Survey

Tic Tac Toe

X | | O | O | X | | "X _ _" "O O X" "_ _ _" "X _ _ O O X _ _ _" The board

X | | O | O | X | | "X _ _ O O X _ _ _" Triples (another representation to help the search for possible moves ) ()x23oox789xo72o83x9xo93o7

Higher order function (HOFs) A HOF is a procedure that takes a procedure as an argument. There are three main ones that work with words and sentences: –every – do something to each element –keep – return only certain elements –accumulate – combine the elements

A definition of every (define (my-every proc ws) (if (empty? ws) '() (se (proc (first ws)) (my-every (bf ws)) ))) Every does a lot of work for you: Checking the conditional Returning the proper base case Combing the various recursive steps Invoking itself recursively on a smaller problem

Which HOFs would you use to write these? 1)capitalize-proper-names (c-p-n '(mr. smith goes to washington))  (mr. Smith goes to Washington) 2)count-if (count-if odd? '( ))  3 3)longest-word (longest-word '(I had fun on spring break))  spring 4)count-vowels-in-each (c-e-l '(I have forgotten everything))  ( ) 5)squares-greater-than-100 (s-g-t-100 '( )  ( ) 6)sum-of-squares (sos '( )  30 7)successive-concatenation (sc '(a b c d e)  (a ab abc abcd abcde)

Write successive-concatenation (sc '(a b c d e))  (a ab abc abcd abcde) (sc '(the big red barn))  (the thebig thebigred thebigredbarn) (define (sc sent) (accumulate (lambda ?? ) sent))

HOF: Base cases can be confusing What does (every square '()) return? –(every square "") –(every square "12345") What about (keep odd? '()) –(keep odd? "") How about (accumulate + ' ()) –(accumulate + "") –(accumulate * '()) –(accumulate word '(a)) –(accumulate + '(a) –(accumulate word '(a b)) –(accumulate + '(a b))

lambda "lambda" is a special form that returns a function: (lambda (param1 param2 …) statement1 statement2 ) (lambda (x) (* x x)  [a function] (every (lambda (x) (* x x) '( ))  ( )

Can a function defined by a lambda be recursive? (lambda (sent) (if (empty? sent) '() (se (square (first sent)) (???? (bf sent)))))

When do you NEED lambda? 1.When you need the context (inside a two-parameter procedure) (add-suffix '-is-great '(nate sam mary))  (nate-is-great sam-is-great mary-is-great) 2.When you need to make a function on the fly

Procedures that make procedures Generally, name procedures that create procedures "make-XXX" (make-bookends 'o)  #[closure arglist=(inner-wd) d7d0e0] ((make-bookends 'o) 'hi)  ohio ((make-bookends 'to) 'ron)  toronto (define tom-bookend (make-bookends 'tom)) (tom-bookends "")  tomtom