CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 24: Review for lists, map and member.

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

Murach, Chapter 6. Murach’s Visual Basic 2008, C6© 2008, Mike Murach & Associates, Inc. Slide 2.
Introduction to Programming Lecture 31. Operator Overloading.
Lisp II. How EQUAL could be defined (defun equal (x y) ; this is how equal could be defined (cond ((numberp x) (= x y)) ((atom x) (eq x y)) ((atom y)
Lisp II. How EQUAL could be defined (defun equal (x y) ; this is how equal could be defined (cond ((numberp x) (= x y)) ((atom x) (eq x y)) ((atom y)
CSE 341 Lecture 16 More Scheme: lists; helpers; let/let*; higher-order functions; lambdas slides created by Marty Stepp
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 4: Review Conditional & Word Stuff.
Helper functions: when extra arguments are needed Consider this problem: we want a function index_items that takes a list L and gives a number to each.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 17: HOF and Tick-Tack-Toe.
1 Introduction of Lisp function e.g. (+ 2 2) Shift+Enter Execute …… (+ 1 2) 3 ( ) 15 (- 1 6) -5 ( ) -5 (- ( ) (+
CS3 Fall 2005 Lecture 11: Finish higher order functions Midterm Prep.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 18: HOF.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 26: Printing and Stuff.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 14: Number Spelling Mini-project.
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.
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.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 6: Mini-Project Prep.
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.
LISP primitives on sequences FIRST (or CAR) and REST (or CDR) take lists apart. Consider the list (First day of the semester). * (first '(First day of.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 13: Bugs and Two Stage Recursion.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 20: Tree Recursion.
Introductory Lisp Programming Lecture # 2 Main Topics –Basic Lisp data types –Lisp primitives –Details of list handling Cons cells (boxes) & their representation.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 1: Introduction & Administration.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 11: Accumulating Recursion.
Feb 28More complicated recursions March 7Tree recursion, etc. Number-spelling Miniproject (#2) March 14Higher order procedures March 21Spring Break March.
מבוא מורחב - שיעור 81 Lecture 8 Lists and list operations (continue).
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 8: Recursion.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 9: Recursion Rocks!
CS 3 Final Review Gilbert Chou, Jenny Franco and Colleen Lewis December 14, pm GPB.
Symbolic Expressions (S Expressions) Syntax: Opening and Closing parenthesis having elements in between. List represented in LISP: (A B2 C3 Shahid) (A.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 2: Review – Writing Procedures.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 16: Let and Lambda.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 25: Trees and Generalized Lists.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 27: Review – most children and truth about cons.
Slide 1 CS3 Fall 2005 Lecture 9: Higher Order Functions.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 7: Review.
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,
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 15: Procedures as Arguments.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 5: Difference Between Dates Case Study.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 3: Conditional Expressions.
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.
Cs1120 Fall 2009 David Evans Lecture 20: Programming with State.
For Monday Read Chapter 3 Homework: –Lisp handout 2.
14-October-2002cse Lists © 2002 University of Washington1 Lists CSE 413, Autumn 2002 Programming Languages
You can access the members of a list with the functions car (or first) and cdr (or rest): (setf list '(a b c)) (car list) ⇒ a (first list) ⇒ a (cdr list)
CS 603: Programming Language Organization Lecture 9 Spring 2003 Department of Computer Science University of Alabama Joel Jones.
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.
CS61A Lecture Colleen Lewis. Clicker poll Do you feel comfortable posting questions to piazza? A)Yes with my classmates and instructors.
Grade 7 5 Parts of a story Watch the video; in the notebook write down 5 parts of a story: 1.________________ 2.________________ 3.________________ 4.________________.
Additional Scheme examples
CS 550 Programming Languages Jeremy Johnson
Lewis Dot Structures.
Racket CSC270 Pepper major portions credited to
CS 270 Math Foundations of CS Jeremy Johnson
6.001 SICP Data abstractions
Lecture 8: Recursion Practice CS200: Computer Science

Lecture #8 מבוא מורחב.
Explicit Application of Procedures, and Explicit Evaluation
topics mutable data structures
List and list operations (continue).
Can you put the symbols in?
Lecture # , , , , מבוא מורחב.
Cat.
CS 403: Programming Languages
Streams… …row, row, row your boat….
LISP primitives on sequences
Presentation transcript:

CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 24: Review for lists, map and member

Today Midterms grades are up! Mean = 22.9/36 Review of List stuff list cons Append member versus member? HOFs for Lists map filter reduce

list Takes any number of arguments and puts them in a list

list Examples (list ‘cat ‘dog)  ‘(cat dog) (list ‘(cat) ‘(dog))  ‘((cat) (dog)) (list ‘(cat) ‘dog)  ‘((cat) dog) (list ‘cat ‘(dog))  ‘(cat (dog)) (list ‘cat ‘())  ‘(cat ()) (list ‘() ‘dog)  ‘(() dog) (list ‘(cat ()) ‘dog)  ‘((cat ()) dog)

cons Takes two arguments Makes the first arg the car of the new list Makes the second arg the cdr of the new list The second argument MUST be a list

cons Examples (cons ‘cat ‘( dog ))  ‘(cat dog) (cons ‘(cat) ‘( dog ))  ‘((cat) dog) (cons ‘cat ‘())  ‘(cat) (cons ‘() ‘( () dog ))  ‘(() () dog) (cons ‘(cat) ‘dog  ‘((cat). dog)

append Takes two lists and turns them into one Both arguments MUST be lists

append Examples (append ‘(cat) ‘(dog))  ‘(cat dog) (append ‘(cat) ‘())  ‘(cat) (append ‘() ‘(dog))  ‘(dog) (append ‘(cat) ‘(()))  ‘(cat ()) (append ‘(()())‘(dog))  ‘(() () dog)

accessors sentence & word stuff list stuff firstcar butfirstcdr last  Butlast 

other procedures sentence & word stuff list stuff empty?null? sentence?list? itemlist-ref sentencelist

other procedures sentence & word stuff list stuff member?member everymap keepfilter accumulatereduce

member? versus member For sentences member? returns #t or #f For lists member returns the rest of the list after that element or #f

member (member 'a '(bbb a c))  (a c) (member 'x '(bbb a c))  #f (member '(mike clancy) '((clint ryan) (mike clancy) (emily watt)) )  ((mike clancy) (emily watt)) (member ‘clancy '((clint ryan) (mike clancy) (emily watt)) )  #f

map ( map procedure list1 list2… ) procedure a procedure that takes in some # of arguments Some # of sents The number of sentences MUST match the number of arguments that the procedure takes

map (define (add-2-nums x y) (+ x y)) (map add-2-nums ‘(1 2 3) ‘(4 5 6))  ‘(5 7 9)

map (define (add-3-nums x y z) (+ x y z)) (map add-3-nums ‘(1 2 3) ‘(4 5 6) ‘(7 8 9))  ‘( )

map (map cons ‘(1 2 3) ‘((4) (5) (6)))  ‘((1 4) (2 5) (3 6)