CS 3 Final Review Gilbert Chou, Jenny Franco and Colleen Lewis December 14, 2008 1-4pm GPB.

Slides:



Advertisements
Similar presentations
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 5. 2 List Utilities Scheme built-in procedures –(list x y z...) –(list-ref lst index) –(length lst) –(append.
Advertisements

Lisp. Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks.
CSE 3341/655; Part 4 55 A functional program: Collection of functions A function just computes and returns a value No side-effects In fact: No program.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
1 Programming Languages and Paradigms Lisp Programming.
CSE 341 Lecture 16 More Scheme: lists; helpers; let/let*; higher-order functions; lambdas slides created by Marty Stepp
CS 116 Tutorial 2 Functional Abstraction. Reminders Assignment 2 is due this Wednesday at Noon.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
מבוא מורחב - שיעור 91 Lecture 9 Lists continued: Map, Filter, Accumulate, Lists as interfaces.
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 7 1. Outline More list examples Symbols 2.
Slide 1 CS3 Fall 2005 Lecture week 13: Introduction to the Big Project.
6.001 SICP SICP – October HOPs, Lists, Trees Trevor Darrell 32-D512 Office Hour: W web page:
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.
6.001 SICP SICP – September ? 6001-Introduction Trevor Darrell 32-D web page: section.
CS 330 Programming Languages 11 / 20 / 2007 Instructor: Michael Eckmann.
Chapter 15 Functional Programming Languages. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Introduction Design of imperative languages is.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 20: Tree Recursion.
CS 330 Programming Languages 11 / 18 / 2008 Instructor: Michael Eckmann.
מבוא מורחב - שיעור 81 Lecture 8 Lists and list operations (continue).
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.
מבוא מורחב 1 Lecture #8. מבוא מורחב 2 Shall we have some real fun.. Lets write a procedure scramble.. (scramble (list )) ==> ( ) (scramble.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 15: Procedures as Arguments.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 24: Review for lists, map and member.
Midterm Review Gilbert Chou
General pattern for selecting some elements of a list This negatives example illustrates a general pattern: If you want a function which selects some elements.
Spring 2008Programming Development Techniques 1 Topic 6 Hierarchical Data and the Closure Property Section September 2008.
1 Lisp Functions –Built-in functions –Defining functions –Function Evaluation and Special Forms defun, if Control statements –Conditional if, cond –Repetition.
Functional Programming in Scheme and Lisp. Overview In a functional programming language, functions are first class objects. You can create them, put.
1 Lecture 16: Lists and vectors Binary search, Sorting.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 7.
CS 152: Programming Language Paradigms February 17 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
Scheme & Functional Programming. ( ) >> 64 ( ) >> 666 (* ) >> 1200 (+ (* 3 5) (- 10 6)) >> 19.
Functional Programming and Lisp. Overview In a functional programming language, functions are first class objects. In a functional programming language,
1 Append: process  (append list1 list2) (cons 1 (append ‘(2) list2)) (cons 1 (cons 2 (append ‘() list2))) (cons 1 (cons 2 list2)) (define (append list1.
Practice session #6: 1. Sequence operations 2. Partial evaluation with currying 3. Lazy-lists.
Functional Programming in Scheme and Lisp.
COP4020 Programming Languages Functional Programming Prof. Xin Yuan.
12/9/2010 Course A201: Introduction to Programming.
18-October-2002cse Symbols © 2002 University of Washington1 Symbols CSE 413, Autumn 2002 Programming Languages
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
Class 8: Recursing on Lists David Evans cs1120 Fall 2009.
Fall 2008Programming Development Techniques 1 Topic 8 Sequences as Conventional Interfaces Section October 2008.
CS 330 Programming Languages 11 / 28 / 2006 Instructor: Michael Eckmann.
CS61A Lecture Colleen Lewis. Clicker poll Where do you think you’re learning the most? I assume you’ll learn the most in lab & disc (so.
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 6. 2 List Utilities Scheme built-in procedures –(list x y z...) –(list-ref lst index) –(length lst) –(append.
Forms Writing your own procedures CS 480/680 – Comparative Languages.
C H A P T E R E I G H T Functional Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
CS 152: Programming Language Paradigms February 12 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
Additional Scheme examples
CS 550 Programming Languages Jeremy Johnson
Class 11: Two-argument recursion
CSC 533: Programming Languages Spring 2017
Racket CSC270 Pepper major portions credited to
Chapter 15 – Functional Programming Languages
CSE 341 Lecture 20 Mutation; memoization slides created by Marty Stepp
CSC 533: Programming Languages Spring 2016
CS 270 Math Foundations of CS Jeremy Johnson
CSC 533: Organization of Programming Languages Spring 2008
Binomial Priority Queues
Lecture #8 מבוא מורחב.
Streams, Delayed Evaluation and a Normal Order Interpreter
Announcements Quiz 5 HW6 due October 23
List and list operations (continue).
Lecture # , , , , מבוא מורחב.
Binomial Priority Queues
CSC 533: Organization of Programming Languages Spring 2007
Rewriting your function using map and foldr
Lisp.
More Scheme CS 331.
Lecture 8: Recursing Lists CS150: Computer Science
Presentation transcript:

CS 3 Final Review Gilbert Chou, Jenny Franco and Colleen Lewis December 14, pm GPB

Warm-up! What is your favorite color? Option A: Brown Option B: Orange Option C: Yellow Option D: Green

Predict the Output

Predict the output ((repeated bf 3) '(cat dog hat bat))  _____ Option A: Error Option B: ‘bat Option C: bat Option D: (bat)

Predict the output ((repeated bf 3) '(cat dog hat bat))  _____ Option A: Error Option B: ‘bat Option C: bat Option D: (bat) butfirst of a sentence ALWAYS returns a sentence Never quote the output of scheme! (repeated bf 3) returns a procedure that takes a word or a sentence.

Predict the output (cons ‘() (list ‘() (cons ‘() ‘())))  _____ Option A: Error Option B: ( () () (()) ) Option C: ( () () () () ) Option D: ( () () (() ()) )

Predict the output (cons ‘() (list ‘() (cons ‘() ‘())))  _____ Option A: Error Option B: ( () () (()) ) Option C: ( () () () () ) Option D: ( () () (() ()) ) Review what cons, append and list do…

Predict the output (empty? ‘())  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: no idea!

Predict the output (empty? ‘())  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: no idea! empty? returns true for empty sentences and words Don’t use it with lists!

Predict the output (empty? “”)  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: no idea!

Predict the output (empty? “”)  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: no idea! empty? returns true for empty sentences and words Don’t use it with lists!

Predict the output (null? “”)  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: no idea!

Predict the output (null? “”)  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: no idea! null? returns true for null lists Don’t use it with words and sentences!

Predict the output (null? (cons “” ‘()))  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: no idea!

Predict the output (null? (cons “” ‘()))  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: no idea! An empty word counts as something inside the list. So – it is not null?

Predict the output (assoc ‘x ‘((a 1) (b 2) (x 3) (x 4))  _____ Option A: Error Option B: 3 Option C: (x 3) Option D: (x 4)

Predict the output (assoc ‘x ‘((a 1) (b 2) (x 3) (x 4))  _____ Option A: Error Option B: 3 Option C: (x 3) Option D: (x 4) assoc just returns the first match. Returns the entire pair – not just the car of the cdr

Predict the output (member ‘x ‘(a b c d x e f g))  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: something else

Predict the output (member ‘x ‘(a b c d x e f g))  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: something else Returns: (x e f g) member returns the rest of the sentence starting with the thing you were looking for. It is a semi-predicate member? returns just #t or #f

Predict the output (member? ‘x ‘(a b c d x e f g))  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: something else

Predict the output (member? ‘x ‘(a b c d x e f g))  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: something else member returns the rest of the sentence starting with the thing you were looking for. It is a semi-predicate member? returns just #t or #f

Predict the output (member? ‘x ‘(a b c d (x) e f g))  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: something else

Predict the output (member? ‘x ‘(a b c d (x) e f g))  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: something else member doesn’t look inside of sublists

Predict the output (cons 1 2)  _____ Option A: Error Option B: (1 2) Option C: (1. 2) Option D: something else

Predict the output (cons 1 2)  _____ Option A: Error Option B: (1 2) Option C: (1. 2) Option D: something else The second argument to cons should be a list otherwise you end up with this weird dot. Remember cons pulls out the “underwear” of the second argument and drops the first argument in.

Predict the output (map cons 1 ‘(2))  _____ Option A: Error Option B: (1 2) Option C: (1. 2) Option D: ((1 2))

Predict the output (map cons 1 ‘(2))  _____ Option A: Error Option B: (1 2) Option C: (1. 2) Option D: ((1 2)) Map takes in a procedure and one or more LISTS! There should be the same number of lists as there are arguments that the procedure takes in!

Predict the output (map cons ‘(1) ‘(2))  _____ Option A: Error Option B: (1 2) Option C: (1. 2) Option D: ((1 2))

Predict the output (map cons ‘(1) ‘(2))  _____ Option A: Error Option B: (1 2) Option C: (1. 2) Option D: ((1. 2)) Map takes the car of each list and calls the procedure cons with them. i.e. (cons 1 2) it does that for each element in the lists and puts the result in a list!

Fill in the blank __________________  ((1 2) (A B)) Option A: (map cons ‘(1 A) ‘((2) (B))) Option B: (map cons ‘((1) (A)) ‘((2) (B))) Option C: (map cons ‘(1 A) ‘(2 B)) Option D: something else

Fill in the blank __________________  ‘((1 2) (A B)) Option A: (map cons ‘(1 A) ‘((2) (B))) Option B: (map cons ‘((1) (A)) ‘((2) (B))) Option C: (map cons ‘(1 A) ‘(2 B)) Option D: something else (list (cons 1 ‘(2)) (cons A ‘(B))) (list (cons ‘(1) ‘(2)) (cons ‘(A) ‘(B))) (list (cons 1 2) (cons A B))

Predict the output (=‘x ‘x)  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: something else

Predict the output (=‘x ‘x)  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: something else = only works with numbers! For words/sentences use equal?

Predict the output (=‘1 1)  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: something else

Predict the output (=‘1 1)  _____ Option A: Error Option B: #t ;; True Option C: #f ;; False Option D: something else Numbers are words! The quote is implicit on numbers

Predict the output (every first ‘awesome)  _____ Option A: Error Option B: a Option C: awesome Option D: (a w e s o m e)

Predict the output (every first ‘awesome)  _____ Option A: Error Option B: a Option C: awesome Option D: (a w e s o m e) Every returns a sentence even if it is given a word!

1 (define (depth lst) 2 (if (not (list? lst)) (max (map (+ depth 1) lst)))) Option A: Error Option B: 0 Option C: 1 Option D: something else (depth )  ________

1 (define (depth lst) 2 (if (not (list? lst)) (max (map (+ depth 1) lst)))) Option A: Error Option B: 0 Option C: 1 Option D: something else (depth )  ________

1 (define (depth lst) 2 (if (not (list? lst)) (max (map (+ depth 1) lst)))) Option A: Error Option B: 0 Option C: 1 Option D: something else (depth ‘((a)(b)))  ________

1 (define (depth lst) 2 (if (not (list? lst)) (max (map (+ depth 1) lst)))) Option A: Error Option B: 0 Option C: 1 Option D: something else (depth ‘((a)(b)))  ________

1 (define (depth lst) 2 (if (not (list? lst)) (max (map (+ depth 1) lst)))) Option A: 1 Option B: 2 Option C: 3 Option D: 4 Which line has an error? ________

1 (define (depth lst) 2 (if (not (list? lst)) (max (map (+ depth 1) lst)))) Option A: 1 Option B: 2 Option C: 3 Option D: 4 Which line has an error? ________

1 (define (depth lst) 2 (if (not (list? lst)) (max (map (+ depth 1) lst)))) Correct the error! _____________________________

1 (define (depth lst) 2 (if (not (list? lst)) (max (map (+ depth 1) lst)))) New line 4: (+ 1 (reduce max (map depth lst)))

List or Sentence?

Would you use this with Lists or Sentences? item Option A: lists Option B: sentences Option C: neither Option D: both

Would you use this with Lists or Sentences? item Option A: lists Option B: sentences Option C: neither Option D: both list-ref for lists item for sentences/words

Would you use this with Lists or Sentences? assoc Option A: lists Option B: sentences Option C: neither Option D: both

Would you use this with Lists or Sentences? assoc Option A: lists Option B: sentences Option C: neither Option D: both Assoc lists are LISTS

Would you use this with Lists or Sentences? first Option A: lists Option B: sentences Option C: neither Option D: both

Would you use this with Lists or Sentences? first Option A: lists Option B: sentences Option C: neither Option D: both car for lists first for sentences/words

Would you use this with Lists or Sentences? reduce Option A: lists Option B: sentences Option C: neither Option D: both

Would you use this with Lists or Sentences? reduce Option A: lists Option B: sentences Option C: neither Option D: both reduce for lists accumulate for sentences/words

Would you use this with Lists or Sentences? map Option A: lists Option B: sentences Option C: neither Option D: both

Would you use this with Lists or Sentences? map Option A: lists Option B: sentences Option C: neither Option D: both map for lists (and it is way cooler than every !) every for sentences/words

Would you use this with Lists or Sentences? filter Option A: lists Option B: sentences Option C: neither Option D: both

Would you use this with Lists or Sentences? filter Option A: lists Option B: sentences Option C: neither Option D: both filter for lists keep for sentences/words