Warm-up! CS 3 Final Review. Predict the output. Predict the Output. Predict the output. Predict the output. What is your favorite color?

Similar documents
Discussion 4. Data Abstraction and Sequences

CS3 Midterm 2 Summer 2008

CS3: Introduction to Symbolic Programming. Lecture 14: Lists Scheme vs. other programming languages.

PAIRS AND LISTS 6. GEORGE WANG Department of Electrical Engineering and Computer Sciences University of California, Berkeley

Sample midterm 1 #1. Problem 1 (What will Scheme print?).

SCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0))

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

YOUR NAME PLEASE: *** SOLUTIONS ***

Lisp. Versions of LISP

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

CS3: Introduction to Symbolic Programming. Lecture 14: Lists.

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003

CS 314 Principles of Programming Languages. Lecture 16

Scheme Basics > (butfirst '(help!)) ()

CS 61A Discussion 8: Scheme. March 23, 2017

61A LECTURE 18 SCHEME. Steven Tang and Eric Tzeng July 24, 2013

Computer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs. Lexical addressing

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

CS3L Summer 2011 Final Exam, Part 2 You may leave when finished; or, you must stop promptly at 12:20

Functional Programming. Pure Functional Languages

CS 314 Principles of Programming Languages

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

CS 3 Midterm 1 Review

STREAMS 10. Basics of Streams. Practice with Streams COMPUTER SCIENCE 61AS. 1. What is a stream?


Streams, Delayed Evaluation and a Normal Order Interpreter. CS 550 Programming Languages Jeremy Johnson

Intro. Scheme Basics. scm> 5 5. scm>

Macros & Streams Spring 2018 Discussion 9: April 11, Macros

CS450 - Structure of Higher Level Languages

regsim.scm ~/umb/cs450/ch5.base/ 1 11/11/13

Procedural abstraction SICP Data abstractions. The universe of procedures forsqrt. Procedural abstraction example: sqrt

Defining Recursive Procedures. Lecture 8: Recursing Lists. list? Tracing list? sumlist. Defining Recursive Procedures on Lists

CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.

6.001: Structure and Interpretation of Computer Programs

Introduction to Scheme

Functional Programming. Pure Functional Programming

STREAMS 10. Basics of Streams. Practice with Streams COMPUTER SCIENCE 61AS. 1. What is a stream? 2. How does memoization work?

CSE 341 Section Handout #6 Cheat Sheet

Representing Images as Lists of Spots

User-defined Functions. Conditional Expressions in Scheme

Functional Programming - 2. Higher Order Functions

A Brief Introduction to Scheme (II)

Functional Programming. Pure Functional Languages

CS 61A Midterm #2 ver March 2, 1998 Exam version: A. Your name. login: cs61a- Discussion section number. TA's name

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

CSE413 Midterm. Question Max Points Total 100

Administrivia. Simple data types

CS 61A, Fall, 2002, Midterm #2, L. Rowe. 1. (10 points, 1 point each part) Consider the following five box-and-arrow diagrams.

Warm-up and Memoization

Documentation for LISP in BASIC

CS 275 Name Final Exam Solutions December 16, 2016

cs61amt2_4 CS 61A Midterm #2 ver March 2, 1998 Exam version: A Your name login: cs61a- Discussion section number TA's name

Introduction to Functional Programming

CS61A Midterm 2 Review (v1.1)

CONCEPTS OF PROGRAMMING LANGUAGES Solutions for Mid-Term Examination

Deferred operations. Continuations Structure and Interpretation of Computer Programs. Tail recursion in action.

CS3: Introduction to Symbolic Programming. Lecture 14: Lists Scheme vs. other programming languages.

Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions. 1 Calculator. calc> (+ 2 2) 4

Programming Languages. Thunks, Laziness, Streams, Memoization. Adapted from Dan Grossman s PL class, U. of Washington

CS3 Midterm 1 Fall 2006

CS61A, Fall/1999 Midterm #1 Professor Brian Harvey

(scheme-1) has lambda but NOT define

Common LISP-Introduction

CS 61A Midterm #2 - October 5, 1998

Racket Pattern Matching

Scheme Quick Reference

Below are example solutions for each of the questions. These are not the only possible answers, but they are the most common ones.

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.

HIERARCHICAL DATA What is a Tree? How is it different from a Deep List? When would you use one over the other?

Scheme Quick Reference

Sample Final Exam Questions

Scheme: Strings Scheme: I/O

Lists in Lisp and Scheme

SCHEME The Scheme Interpreter. 2 Primitives COMPUTER SCIENCE 61A. October 29th, 2012


Read and fill in this page now

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

Quicksort. Alternative Strategies for Dividing Lists. Fundamentals of Computer Science I (CS F)

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

CSc 520. Principles of Programming Languages 7: Scheme List Processing

CS 61B, Spring 1999 MT3 Professor M. Clancy

CS3 Midterm 2 Standards and Solutions

Structure and Interpretation of Computer Programs

SCHEME AND CALCULATOR 5b

The Interpreter + Calling Functions. Scheme was designed by people. The Interpreter + Calling Functions. Clickers. Parentheses Matter We asked scheme

(first (hello)) (hello) CS61A Lecture 2. Computer Science. Hierarchy of Abstraction. Functions. REVIEW: Two Types of( s so far

CSC 533: Programming Languages. Spring 2015

Read and fill in this page now. Your lab section day and time: Name of the person sitting to your left: Name of the person sitting to your right:

This exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions.

CSc 520 Principles of Programming Languages. Examining Lists. Constructing Lists... 7: Scheme List Processing

Func%onal Programming in Scheme and Lisp

PROBLEM SOLVING 11. July 24, 2012

Announcements. The current topic: Scheme. Review: BST functions. Review: Representing trees in Scheme. Reminder: Lab 2 is due on Monday at 10:30 am.

Func%onal Programming in Scheme and Lisp

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page.

Fall Semester, The Metacircular Evaluator. Today we shift perspective from that of a user of computer langugaes to that of a designer of

Types of recursion. Structural vs. general recursion. Pure structural recursion. Readings: none. In this module: learn to use accumulative recursion

COMPUTER SCIENCE IN THE NEWS. CS61A Lecture 21 Scheme TODAY REVIEW: DISPATCH DICTIONARIES DISPATCH DICTIONARIES 7/27/2012

Transcription:

Warm-up! What is your favorite color? CS 3 Final Review Gilbert Chou, Jenny Franco and Colleen Lewis December 14, 2008 1-4pm GPB Brown Orange Yellow Green ((repeated bf 3) '(cat dog hat bat)) Predict the Output bat bat (bat) ((repeated bf 3) '(cat dog hat bat)) (cons () (list () (cons () ()))) bat bat (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. ( () () (()) ) ( () () () () ) ( () () (() ()) ) 1

(cons () (list () (cons () ()))) (empty? ()) ( () () (()) ) ( () () () () ) ( () () (() ()) ) Review what cons, append and list do (empty? ()) (empty? ) empty? returns true for empty and words Don t use it with! (empty? ) (null? ) empty? returns true for empty and words Don t use it with! 2

(null? ) (null? (cons ())) null? returns true for null Don t use it with words and! (null? (cons ())) (assoc x ((a 1) (b 2) (x 3) (x 4)) An empty word counts as something inside the list. So it is not null? 3 (x 3) (x 4) (assoc x ((a 1) (b 2) (x 3) (x 4)) (member x (a b c d x e f g)) 3 (x 3) assoc just returns the first match. Returns the entire pair not just the car of the cdr (x 4) 3

(member x (a b c d x e f g)) (member? x (a b c d x e f g)) 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 (member? x (a b c d x e f g)) (member? x (a b c d (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 (member? x (a b c d (x) e f g)) (cons 1 2) member doesn t look inside of sub (1 2) (1. 2) 4

(cons 1 2) The second argument to cons should be a list otherwise you end up with this weird dot. (map cons 1 (2)) (1 2) (1. 2) Remember cons pulls out the underwear of the second argument and drops the first argument in. (1 2) (1. 2) ((1 2)) (map cons 1 (2)) (map cons (1) (2)) (1 2) (1. 2) ((1 2)) Map takes in a procedure and one or more LISTS! There should be the same number of as there are arguments that the procedure takes in! (1 2) (1. 2) ((1 2)) Fill in the blank (map cons (1) (2)) ((1 2) (A B)) (1 2) (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 and puts the result in a list! (map cons (1 A) ((2) (B))) (map cons ((1) (A)) ((2) (B))) (map cons (1 A) (2 B)) ((1. 2)) 5

Fill in the blank ((1 2) (A B)) (= x x) (map cons (1 A) ((2) (B))) (list (cons 1 (2)) (cons A (B))) (map cons ((1) (A)) ((2) (B))) (list (cons (1) (2)) (cons (A) (B))) (map cons (1 A) (2 B)) (list (cons 1 2) (cons A B)) (= x x) = only works with numbers! For words/ use equal? (= 1 1) (= 1 1) Numbers are words! (every first awesome) The quote is implicit on numbers a awesome (a w e s o m e) 6

(every first awesome) a awesome Every returns a sentence even if it is given a word! 0 1 (a w e s o m e) (depth 1234567) 0 1 0 1 (depth 1234567) (depth ((a)(b))) 1 0 1 2 3 4 (depth ((a)(b))) Which line has an error? 7

1 2 3 Correct the error! 4 Which line has an error? List or Sentence? New line 4: (+ 1 (reduce max (map depth lst))) item item list-ref for item for /words 8

assoc assoc Assoc are LISTS first first car for first for /words reduce reduce reduce for accumulate for /words 9

map map map for (and it is way cooler than every!) every for /words filter filter filter for keep for /words 10