CS116 Tutorial 1 Review of CS115. Reminders Assignment 1 is due Wednesday, January 21th at 12pm (Noon) Submit Assignment 0 if you have not done so already.

Slides:



Advertisements
Similar presentations
Higher-Order Functions and Loops c. Kathi Fisler,
Advertisements

Introduction A function is called higher-order if it takes a function as an argument or returns a function as a result. twice :: (a  a)  a  a twice.
Higher-order functions in ML
Higher-order functions in OCaml. Higher-order functions A first-order function is one whose parameters and result are all "data" A second-order function.
F28PL1 Programming Languages Lecture 14: Standard ML 4.
1 Calling within Static method /* We can call a non static method from a static method but by only through an object of that class. */ class Test1{ public.
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.
CSC 213 – Large Scale Programming. Today’s Goals  Review discussion of merge sort and quick sort  How do they work & why divide-and-conquer?  Are they.
AP Statistics Thursday, 22 January 2015 OBJECTIVE TSW investigate sampling distributions. –Everyone needs a calculator. TESTS are not graded. REMINDERS.
Volume of Triangular Prism. Volume of a Triangular Prism Length Volume of a prism = Area x length Area of triangle = ½ x base x height.
Engineering Statistics ECIV Linear Combinations of Normal Random Variables.
Lists Introduction to Computing Science and Programming I.
Wednesday, 10/2/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/2/02  QUESTIONS (on HW02 – due at 5 pm)??  Today:  Review of parameters  Introduction.
Loops in Scheme, II c. Kathi Fisler, 2001 (early slides assume map/filter)
CS 330 Programming Languages 11 / 18 / 2008 Instructor: Michael Eckmann.
Ormap, andmap, and filter CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.3 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Rewriting your function using map and foldr CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.5 TexPoint fonts used in EMF. Read the TexPoint manual.
CSC 160 Computer Programming for Non-Majors Lecture #5 (continued): More on Writing Functions Prof. Adam M. Wittenstein
CS116 – Tutorial 3 Accumulative Recursion/Runtime.
Table of Contents Factoring - Perfect Square Trinomial A Perfect Square Trinomial is any trinomial that is the result of squaring a binomial. Binomial.
Geometry.
Foldr CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.4 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA © Mitchell.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
Agenda Control Flow Statements Purpose test statement if / elif / else Statements for loops while vs. until statements case statement break vs. continue.
Intermediate Algebra Prerequisite Topics Review Quick review of basic algebra skills that you should have developed before taking this class 18 problems.
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
TUTORIAL 00 Resources and Course Review. a00q4.rkt (define my-tutorial-info (list ………))
Area, Circumference & Volume
Sequences Jordi Cortadella Department of Computer Science.
CS100Lecture 101 Announcements Assignment P2 is due on Thursday Assignment P3 is handed out today Prelim on Monday the 19th. Coming soooooooooon.
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
A Third Look At ML Chapter NineModern Programming Languages, 2nd ed.1.
Chapter 12 Hash Table. ● So far, the best worst-case time for searching is O(log n). ● Hash tables  average search time of O(1).  worst case search.
Rewriting your function using map and foldr CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual.
Exponents. Location of Exponent An An exponent is a little number high and to the right of a regular or base number. 3 4 Base Exponent.
Functions Overview Functions are sequence of statements with its own local variables supports modularity, reduces code duplication Data transfer between.
Lee CSCE 314 TAMU 1 CSCE 314 Programming Languages Haskell: Higher-order Functions Dr. Hyunyoung Lee.
TUTORIAL 8 Generative Recursion. Reminders  Deadline of midterm remark  Assignment 7 due Wed, Mar 18 th.
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
Arrays An array is a data object that can hold multiple objects, all of the same type. We can think of an array as a storage box which has multiple compartments.
9.3 Equations and Absolute Value Goal(s): To solve equations involving absolute value.
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.
Tutorial 9 Iteration. Reminder Assignment 8 is due Wednesday.
CS 330 Programming Languages 11 / 28 / 2006 Instructor: Michael Eckmann.
Location of Exponent An An exponent is the small number high and to the right of a regular or base number. 3 4 Base Exponent.
Haskell Chapter 5, Part II. Topics  Review/More Higher Order Functions  Lambda functions  Folds.
Chapter 10 Lesson 6 Objective: To find the volume of a pyramid and a cone.
Volume of Prisms and Cylinders Algebra 2 1/18/2012.
Lesson 3 Functions. Lesson 3 Functions are declared with function. For example, to calculate the cube of a number function function name (parameters)
An Evolutionary Approach
Types CSCE 314 Spring 2016.
Exponents.
Halting Functions for Tree-Like Structures
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
Agenda Control Flow Statements Purpose test statement
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 12/25/2018.
(early slides assume map/filter)
Higher Order Functions
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019.
CSE 3302 Programming Languages
Recursion, Higher-order-functions
CHAPTER 4: Lists, Tuples and Dictionaries
PROGRAMMING IN HASKELL
Lecture 3: Rules of Evaluation CS200: Computer Science
ormap, andmap, and filter
Introduction to the Lab
Indices By
Presentation transcript:

CS116 Tutorial 1 Review of CS115

Reminders Assignment 1 is due Wednesday, January 21th at 12pm (Noon) Submit Assignment 0 if you have not done so already

Review Local Map Filter Foldr

Local ( local [ (define …) (define …) … ] ;; main body of function here ;; ) Allows your main function to quickly access the functions/constants defined inside local All functions/constants can the main function’s parameters One set of square brackets

Map (map f lst) ;;map:(X -> Y) (listof X) -> (listof Y) Produces a list of values by applying f to each value in lst ;;f: X -> Y Same type! This is an element of lst, not lst itself

What do you notice about the result of using map? The result is always a list Length of the produced list does not change (map f (list x y z … )) => (list (f x) (f y) (f z) … )

Filter (filter f lst) ;;filter:(X -> Bool) (listof X) -> (listof X) Produces a list of values in lst that produces true when f is applied to them ;;f: X -> Bool Same type! This is an element of lst, not lst itself

What do you notice about the result of using filter? The result is always a list Length of the produced list may or may not change

Foldr (foldr combine base lst) ;;foldr:(X Y -> Y) Y (listof X) -> Y Produces the result of applying combine through the lst or produces base if it is empty Same type!

Foldr ;;combine: X Y -> Y (combine x (combine y (combine …(combine z base) The right most expression gets applied to first! Element in lst The “result so far” of applying combine

What do you notice about the result of using foldr? The result can be any type ◦ Numbers ◦ Lists ◦ Strings ◦ Etc.

(define-struct foodcan (height radius weight label)) ;; a Foodcan is (make-foodcan Num Num Num Sym) ;; requires: ;; * height > 0 is height of can in cm ;; * radius > 0 is radius of can in cm ;; * weight > 0 is the weight of can in grams ;; * label indicates contents of can. (define tomatocan (make-foodcan ‘tomatoes)) (define beancan (make-foodcan ‘beans))

Question 1 Using abstract list functions, write a Scheme function supersize-it that consumes a list of foodcan, cans, and produces a new list from it. The height and weight of each new can is twice that of the corresponding consumed foodcan, and the radius and label are unchanged. (define (supersize-it cans) …)

Question 1

Question 2 Using abstract list functions, write a function large-cans that consumes a list of foodcan structures, cans, and a non- negative number, size, and produces a list of the labels on all the cans with weight at least as much as the consumed value. (define (large-cans cans size) …)

Question 2

Question 3 Using abstract list functions, write a function total-volume to compute the total volume of the cans in a list of foodcan. (define (total-volume cans) …)

Question 3

Question 4 Write a function num-above-avg which consumes a list of number, values, and produces the number of values in the list which exceed the average value in list. If the consumed list is empty or of length 1, 0 will be produced. (define (num-above-avg values) …)

Question 4