You must include a signature, purpose, check- expects and complete function definition.

Size: px
Start display at page:

Download "You must include a signature, purpose, check- expects and complete function definition."

Transcription

1 Page 1 of 12 Problem 1: Self- Referential Data Natural Numbers Given the data definition below, design a function that consumes a natural number n and produces a list of the squares of the natural numbers from 1 to n. So, for example, given the natural number 4, the function must produce (list ). If n is 0, the function must produce the empty list. ;; Natural is one of: ;; - 0 ;; - (add1 Natural) ;; interp. a natural number (define N0 0) (define N1 1) (define N2 2) #; (define (fn-for-natural n) (cond [(zero? n) (...)] (... n (fn-for-natural (sub1 n)))])) You must include a signature, purpose, check- expects and complete function definition. ;; Natural -> (listof Natural) ;; produce list of squares of naturals from 1 to n, empty if n is 0 (check-expect (list-sqrs 0) empty) (check-expect (list-sqrs 4) (list )) (define (list-sqrs n) (cond [(zero? n) empty] (append (list-sqrs (sub1 n)) (list (* n n)))])) Or: /1 Signature (no part marks) /1 Purpose /2 check-expects (base, n at least 2 each must be correct) /1 function has reasonable name /1 use of template is evident /1 base case result /2 combination /1 for (cons (list-sqrs (sub1 n)) (list (* n n)) (no other part marks) (define (list-sqrs n) (build-list n (λ(n) (sqr (add1 n)))))

2 Page 2 of 12 Problem 2: Built- in Abstract List Processing Functions a) Given the following partial function design: ;; (listof Image) Natural -> Boolean ;; produce true if all images in loi have a height greater than h (check-expect (all-taller-than? empty 10) true) (check-expect (all-taller-than? (list (square 20 "solid" "blue") (circle 40 "outline" "yellow")) 10) true) (check-expect (all-taller-than? (list (square 3 "solid" "green") (square 100 "outline" "red")) 10) false) (define (all-taller-than? loi h) true) ;stub i) Which abstract built- in function is most appropriate to use in the body of all-taller-than? andmap ii) What's the signature of the function you'll pass to the built- in abstract function? Image -> Boolean iii) Does the function argument to the built- in abstract function need to be a closure? Yes /2 Function /2 Signature /1 Closure?

3 Page 3 of 12 b) Given the following partial function design: ;; (listof String) -> (listof String) ;; produce list of only strings in los that start with "p" (check-expect (start-with-p-only empty) empty) (check-expect (start-with-p-only (list "red" "green" "purple")) (list "purple")) (check-expect (start-with-p-only (list "cat" "dog" "horse")) empty) (check-expect (start-with-p-only (list "purple" "pink")) (list "purple" "pink")) (define (start-with-p-only los) los) ;stub i) Which abstract built- in function is most appropriate to use in the body of start-with-p-only? filter ii) What's the signature of the function you'll pass to the built- in abstract function? String -> Boolean iii) Does the function argument to the built- in abstract function need to be a closure? No /2 Function /2 Signature /1 Closure?

4 Page 4 of 12 c) Given the following partial function design: ;; (listof Image) -> Image ;; overlay all images in loi (check-expect (overlay-all empty) empty-image) (check-expect (overlay-all (list (square 8 "solid" "black") (circle 12 "solid" "white") (triangle 18 "solid" "black"))) (overlay (square 8 "solid" "black") (circle 12 "solid" "white") (triangle 18 "solid" "black") empty-image)) (define (overlay-all loi) empty-image) i) Which abstract built- in function is most appropriate to use in the body of overlay-all? foldr ii) What's the signature of the function you'll pass to the built- in abstract function? Image Image -> Image iii) Does the function argument to the built- in abstract function need to be a closure? No /2 Function /2 Signature /1 Closure?

5 Page 5 of 12 Problem 3: Two One- Ofs The data definition for a person having a name, a biological mother and biological father is provided: (define-struct person (name mother father)) ;; Person is one of: ;; - false ;; - (make-person String Person Person) ;; interp. a person with a name, biological mother ;; and biological father; false means person unknown (define P1 (make-person "Jing" false false)) (define P2 (make-person "Mack" false false)) (define P3 (make-person "Mae" P1 P2)) (define P4 (make-person "Pat" false false)) (define P5 (make-person "Chris" false false)) (define P6 (make-person "Jack" P4 P5)) (define P7 (make-person "Tina" P3 P6)) #; (define (fn-for-person p) (cond [(false? p) (...)] (... (person-name p) (fn-for-person (person-mother p)) (fn-for-person (person-father p)))])) Design a function that consumes a person and a list of names. The function must produce true if the list of names represents a path through the ancestors of the given person and false otherwise. The path must start with the name of the given person. So, in the context of person P7 defined above and pictured here: Jing Mack Pat Chris \ / \ / Mae Jack \ / Tina the following are paths through the ancestor tree: (list "Tina") (list "Tina" "Mae" "Mack") (list "Tina" "Jack" "Chris") - because Tina is at the root of the tree - because Tina is at the root, has a parent named Mae and Mae has a parent named Mack. - because Tina is at the root, has a parent named Jack and Jack has a parent named Chris.

6 Page 6 of 12 The following, however, are not paths through the ancestor tree: (list "Jack") (list "Tina" "Pat") - because Jack is not at the root of the tree - because Tina does not have a parent named Pat Your solution must include signature, purpose, a correctly labeled cross- product of types comments table, check- expects and a complete function definition. The function and check- expects that you design must be consistent with the table! p false (make-person String Person Person) empty true true los (cons String false (... ListOfString) (valid-path? (person-mother p) (rest los)) (valid-path? (person-father p) (rest los))) /1 parameters labeled (consistent with function definition) /1 two correct cases for ListOfString /1 two correct cases for Person /3 three correct base case answers (1 for each) /2 general case (1 each natural recursion w/ correct arguments)

7 Page 7 of 12 ;; Person ListOfString -> Boolean ;; produce true if los is a valid path through p (check-expect (valid-path? false empty) true) (check-expect (valid-path? P7 empty) true) (check-expect (valid-path? false (list "Jane")) false) (check-expect (valid-path? P7 (list "Tina" "Pat")) false) (check-expect (valid-path? P7 (list "Tina" "Mae" "Mack")) true) (define (valid-path? p los) (cond [(empty? los) true] [(false? p) false] (and (string=? (person-name p) (first los)) (or (valid-path? (person-mother p) (rest los)) (valid-path? (person-father p) (rest los))))])) /1 signature /1 purpose /3 check-expect (/1 for each base case) /3 check-expects for general case /1 produces false /1 produces true /1 involves mother and father tree (OK if last two are combined) /2 cond has three cases (no marks for 4) /2 base case questions and answers are correct AND consistent with table (/1 for each) /3 correct combination in general case

8 Page 8 of 12 Problem 4: Designing Abstract Functions from Templates Given the data definition that follows: (define-struct node (name next)) ;; Path is one of: ;; - false ;; - (make-node String Path) ;; interp. a path is either empty (false) or ;; is a node with a name and a next Path (define P1 false) (define P2 (make-node "a" false)) (define P3 (make-node "b" (make-node "a" false))) (define (fn-for-path p) (cond [(false? p) (...)] (... (node-name p) (fn-for-path (node-next p)))])) Design an abstract fold function for Path. You must include the signature, purpose, two check- expects as described below, and complete function definition. You must include two check-expects where each fulfills one of the following requirements: 1) creates a copy of the argument 2) produces a list of the names of all the nodes in the path Please write your answer to this question on the following page.

9 Page 9 of 12 ;;(String X -> X) X Path -> X ;; abstract fold function for Path (check-expect (fold-path make-node false P3) P3) (check-expect (fold-path cons empty P3) (list "b" "a")) (define (fold-path c b p) (cond [(false? p) b] (c (node-name p) (fold-path c b (node-next p)))])) /5 signature (/2 function argument, /1 each other piece) /1 purpose /3 correct check-expect to copy argument (/1 make-node, /1 false, /1 rest) /3 correct check-expect to produce list of names of nodes (/1 cons, /1 empty, /1 rest) /2 correct parameterization of combination function (/1 adding parameter, /1 for passing it in the NR) /1 correct use of combination function parameter /2 correct parameterization of base case (/1 adding parameter, /1 for passing it in the NR) /1 correct use of base case parameter

10 Page 10 of 12 Problem 5: Designing Data Definitions In this problem we imagine that we are working in the domain of human geography and are interested in geographical regions, their sizes and populations. A geographical region has a name, an arbitrary number of sub- regions (which are themselves geographical regions) and an arbitrary number of cities. A city has a name, an area in square kilometres (measured to the nearest square kilometre) and a population (again, the number of people who live there). 1) Design data definitions to represent the information described above. Your data definitions must include an example that represents the geographical region shown in the following diagram: 2) For each data definition, be sure to include struct definitions (if needed), types comments, interpretation statements, examples and template functions.

11 Page 11 of 12 Note: It is not necessary to encapsulate the template functions in a local expression. Do not make use of the built- in data definition (listof ). You must provide a complete data definition for any ListOf (define-struct city (name area pop)) ;; City is (make-city String Natural Natural) ;; interp. a city with a name, geographical area in sq kms and population (define C1 (make-city "Vancouver" )) (define C2 (make-city "Calgary" )) (define C3 (make-city "Edmonton" )) (define C4 (make-city "Whitehorse" )) #; (define (fn-for-city c) (... (city-name c) (city-area c) (city-pop c))) ;; ListOfCity is one of: ;; - empty ;; - (cons City ListOfCity) ;; interp. a list of cities (define LOC1 empty) (define LOC2 (list C1 C2)) #; (define (fn-for-loc loc) (cond [(empty? loc) (...)] (... (fn-for-city (first loc)) (fn-for-loc (rest loc)))]))

12 Page 12 of 12 (define-struct geo-area (name subs loc)) ;; GeoArea is (make-geo-area String ListOfGeoArea ListOfCity) ;; interp. a geographical area with a name, list of sub-regions and list of cities (define G1 (make-geo-area "British Columbia" empty (list C1))) (define G2 (make-geo-area "Alberta" empty (list C2 C3))) (define G3 (make-geo-area "Western Canada" (list G1 G2) (list C4))) #; (define (fn-for-ga ga) (... (geo-area-name ga) (fn-for-loga (geo-area-subs ga)) (fn-for-loc (geo-area-loc ga)))) ;; ListOfGeoArea is one of: ;; - empty ;; - (cons GeoArea ListOfGeoArea) ;; interp. a list of geographical areas (define LOG1 empty) (define LOG2 (list G1 G2)) #; (define (fn-for-loga loga) (cond [(empty? loga) (...)] (... (fn-for-ga (first loga)) (fn-for-loga (rest loga)))])) In general, -1 for each distinct error, unless otherwise noted: /4 arbitrary-arity tree data is represented (/2 for arbitrariness in each of two directions) /2 GeoArea with name, subs, and cities /2 City with name, area, and population /2 differentiating GeoArea and City (either by having separate data definitions or an itemization, or...) (no part marks) /4 types comments are well formed /2 interpretations are clear /3 example that matches "Western Canada" in given diagram In following section, minimum -2 for each distinct error (must be consistent with types comments): /3 NR in templates is correct /3 NMR in templates is correct /2 NH in templates is correct (give these marks if NH not needed)

Expression Values Operators. (string-append a b c ) a, b, c string-append. (substring abcd 0 2) abcd, 0, 2 substring

Expression Values Operators. (string-append a b c ) a, b, c string-append. (substring abcd 0 2) abcd, 0, 2 substring Expressions Expression Values perators (+ 2 3 5) 2 3 5 + (* 3.1 2.5) 3.1, 2.5 * (+ (* 3 2.2) 7) 7, 6.6 *, + (string-append a b c ) a, b, c string-append (circle 20 solid red ) 20, solid, red circle (substring

More information

(add1 3) 4 (check-expect (add1 3) 4)

(add1 3) 4 (check-expect (add1 3) 4) (add1 3) 4 (check-expect (add1 3) 4) ;; A Dict is one of: ;; - '() ;; - (cons (list String String) Dict) ;; Interp: a collection of definitions where each element is a ;; two-element list of a word (first)

More information

From Templates to Folds

From Templates to Folds From Templates to Folds CS 5010 Program Design Paradigms Bootcamp Lesson 6.3 Mitchell Wand, 2012-2014 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

More information

Do a domain analysis by hand-drawing three or more pictures of what the world program will look like at different stages when it is running.

Do a domain analysis by hand-drawing three or more pictures of what the world program will look like at different stages when it is running. How to Design Worlds The How to Design Worlds process provides guidance for designing interactive world programs using big-bang. While some elements of the process are tailored to big-bang, the process

More information

ormap, andmap, and filter

ormap, andmap, and filter ormap, andmap, and filter CS 5010 Program Design Paradigms Bootcamp Lesson 6.3 Mitchell Wand, 2012-2015 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

More information

(add1 3) 4 (check-expect (add1 3) 4)

(add1 3) 4 (check-expect (add1 3) 4) (add1 3) 4 (check-expect (add1 3) 4) (define T 7) (define (q z) (sqr z)) (cond [(> T 3) (q 4)] [else 9]) (cond [(> T 3) (q 4)] [else 9]) -->[const] ^ (cond [(> 7 3) (q 4)] [else 9]) -->[arith] ^^^^^^^

More information

;; ;; Section 1 ;; ;; ;; What is the value of: (+ 2 (* 3 5)) ;; What is the value of: (string-append "Roberto" " " "Luongo")

;; ;; Section 1 ;; ;; ;; What is the value of: (+ 2 (* 3 5)) ;; What is the value of: (string-append Roberto   Luongo) CPSC 110, Fall 2010 Practice Problems for Midterm 1 These problems are intended to provide you with practice exercises for the first midterm. Additional practice problems covering material from week 4

More information

CS 1101 Exam 3 A-Term 2013

CS 1101 Exam 3 A-Term 2013 NAME: CS 1101 Exam 3 A-Term 2013 Question 1: (55) Question 2: (20) Question 3: (25) TOTAL: (100) You have 50 minutes to complete this exam. You do not need to show templates, but you may receive partial

More information

THE UNIVERSITY OF BRITISH COLUMBIA CPSC 110: MIDTERM 1 Part B May 26, Important notes about this examination

THE UNIVERSITY OF BRITISH COLUMBIA CPSC 110: MIDTERM 1 Part B May 26, Important notes about this examination THE UNIVERSITY OF BRITISH COLUMBIA CPSC 110: MIDTERM 1 Part B May 26, 2014 Last Name: First Name: Signature: UBC Student #: Important notes about this examination 1. This exam has two separate parts. Your

More information

How to Design Programs

How to Design Programs How to Design Programs How to (in Racket): represent data variants trees and lists write functions that process the data See also http://www.htdp.org/ 1 Running Example: GUIs Pick a fruit: Apple Banana

More information

Module 8: Local and functional abstraction

Module 8: Local and functional abstraction Module 8: Local and functional abstraction Readings: HtDP, Intermezzo 3 (Section 18); Sections 19-23. We will cover material on functional abstraction in a somewhat different order than the text. We will

More information

CS115 - Module 10 - General Trees

CS115 - Module 10 - General Trees Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, Sections 15 and 16. Arithmetic Expressions Recall with binary trees we could represent an expression containing binary

More information

Trees. Binary arithmetic expressions. Visualizing binary arithmetic expressions. ((2 6) + (5 2))/(5 3) can be defined in terms of two smaller

Trees. Binary arithmetic expressions. Visualizing binary arithmetic expressions. ((2 6) + (5 2))/(5 3) can be defined in terms of two smaller Trees Readings: HtDP, sections 14, 15, 16. We will cover the ideas in the text using different examples and different terminology. The readings are still important as an additional source of examples.

More information

The Design Recipe Fall 2017

The Design Recipe Fall 2017 CS17 Integrated Introduction to Computer Science Hughes The Design Recipe Fall 2017 Contents 1 Design Recipe Steps 1 2 An OCaml Example 6 1 Design Recipe Steps This PDF outlines the steps to writing the

More information

Trees. Readings: HtDP, sections 14, 15, 16.

Trees. Readings: HtDP, sections 14, 15, 16. Trees Readings: HtDP, sections 14, 15, 16. We will cover the ideas in the text using different examples and different terminology. The readings are still important as an additional source of examples.

More information

The Design Recipe Fall 2018

The Design Recipe Fall 2018 CS17 Integrated Introduction to Computer Science Klein The Design Recipe Fall 2018 Contents 1 Design Recipe Steps 1 2 Another Racket Example 6 3 An OCaml Example 6 4 Another OCaml Example 8 1 Design Recipe

More information

The Typed Racket Guide

The Typed Racket Guide The Typed Racket Guide Version 5.3.6 Sam Tobin-Hochstadt and Vincent St-Amour August 9, 2013 Typed Racket is a family of languages, each of which enforce

More information

The purpose of this lesson is to familiarize you with the basics of Racket (a dialect of Scheme). You will learn about

The purpose of this lesson is to familiarize you with the basics of Racket (a dialect of Scheme). You will learn about Lesson 0.4 Introduction to Racket Preliminaries The purpose of this lesson is to familiarize you with the basics of Racket (a dialect of Scheme). You will learn about Expressions Numbers, Booleans, and

More information

Typed Racket: Racket with Static Types

Typed Racket: Racket with Static Types Typed Racket: Racket with Static Types Version 5.0.2 Sam Tobin-Hochstadt November 6, 2010 Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type

More information

CMSC 131A, Midterm 1 (Practice) SOLUTION. Fall 2017

CMSC 131A, Midterm 1 (Practice) SOLUTION. Fall 2017 CMSC 131A, Midterm 1 (Practice) SOLUTION Fall 2017 Question Points 1 10 2 10 3 10 4 20 5 10 6 20 7 20 Total: 100 This test is open-book, open-notes, but you may not use any computing device other than

More information

Case Study: Undefined Variables

Case Study: Undefined Variables Case Study: Undefined Variables CS 5010 Program Design Paradigms Bootcamp Lesson 7.4 Mitchell Wand, 2012-2017 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International

More information

Modern Programming Languages. Lecture LISP Programming Language An Introduction

Modern Programming Languages. Lecture LISP Programming Language An Introduction Modern Programming Languages Lecture 18-21 LISP Programming Language An Introduction 72 Functional Programming Paradigm and LISP Functional programming is a style of programming that emphasizes the evaluation

More information

Lists. CS 5010 Program Design Paradigms Bootcamp Lesson 4.1

Lists. CS 5010 Program Design Paradigms Bootcamp Lesson 4.1 Lists CS 5010 Program Design Paradigms Bootcamp Lesson 4.1 Mitchell Wand, 2012-2017 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. 1 Module 04 Basic

More information

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs CS 61A Fall 2016 Structure and Interpretation of Computer Programs Final INSTRUCTIONS You have 3 hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator, except

More information

Trees. Example: Binary expression trees. Example: Evolution trees. Readings: HtDP, sections 14, 15, 16.

Trees. Example: Binary expression trees. Example: Evolution trees. Readings: HtDP, sections 14, 15, 16. Trees Readings: HtDP, sections 14, 15, 16. We will cover the ideas in the text using different examples and different terminology. The readings are still important as an additional source of examples.

More information

CS 135 Fall 2018 Final Exam Review. CS 135 Fall 2018 Final Exam Review 1

CS 135 Fall 2018 Final Exam Review. CS 135 Fall 2018 Final Exam Review 1 CS 135 Fall 2018 Final Exam Review CS 135 Fall 2018 Final Exam Review 1 Final Exam Information The final exam will be held on Saturday, December 15 th 9:00AM - 11:30AM in the PAC Check your exam seating

More information

Graphs. Directed graphs. Readings: Section 28

Graphs. Directed graphs. Readings: Section 28 Graphs Readings: Section 28 CS 135 Winter 2018 12: Graphs 1 Directed graphs A directed graph consists of a collection of vertices (also called nodes) together with a collection of edges. An edge is an

More information

Animations that make decisions

Animations that make decisions Chapter 17 Animations that make decisions 17.1 String decisions Worked Exercise 17.1.1 Develop an animation of a simple traffic light. It should initially show a green disk; after 5 seconds, it should

More information

Follow these steps to get started: o Launch MS Access from your start menu. The MS Access startup panel is displayed:

Follow these steps to get started: o Launch MS Access from your start menu. The MS Access startup panel is displayed: Forms-based Database Queries The topic presents a summary of Chapter 3 in the textbook, which covers using Microsoft Access to manage and query an Access database. The screenshots in this topic are from

More information

CS 5010 Program Design Paradigms Lesson 6.1

CS 5010 Program Design Paradigms Lesson 6.1 Lists vs. Structures CS 5010 Program Design Paradigms Lesson 6.1 Mitchell Wand, 2012-2016 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. 1 Module Introduction

More information

Module 5: Lists. Readings: HtDP, Sections 9, 10.

Module 5: Lists. Readings: HtDP, Sections 9, 10. Module 5: Lists Readings: HtDP, Sections 9, 10. Lists are the main tool used in Racket to work with unbounded data. As with conditional expressions and structures, the data definition for lists leads naturally

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2017 EXAMINATIONS CSC 104 H1S Instructor(s): G. Baumgartner Duration 3 hours PLEASE HAND IN No Aids Allowed Student Number: Last (Family)

More information

Graphs. Readings: Section 28. CS 135 Fall : Graphs 1

Graphs. Readings: Section 28. CS 135 Fall : Graphs 1 Graphs Readings: Section 28 CS 135 Fall 2018 12: Graphs 1 Directed graphs A directed graph consists of a collection of vertices (also called nodes) together with a collection of edges. An edge is an ordered

More information

Rewriting your function using map and foldr

Rewriting your function using map and foldr Rewriting your function using map and foldr CS 5010 Program Design Paradigms Bootcamp Lesson 5.5 Mitchell Wand, 2012-2014 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International

More information

CSC 101: Lab Manual#11 Programming Turtle Graphics in Python Lab due date: 5:00pm, day after lab session

CSC 101: Lab Manual#11 Programming Turtle Graphics in Python Lab due date: 5:00pm, day after lab session CSC 101: Lab Manual#11 Programming Turtle Graphics in Python Lab due date: 5:00pm, day after lab session Purpose: The purpose of this lab is to get a little introduction to the process of computer programming

More information

Module 10: General trees

Module 10: General trees Module 10: General trees Readings: HtDP, Sections 15 and 16 CS 115 Winter 2019 10: General trees 1 General trees Binary trees can be used for a large variety of application areas. One limitation is the

More information

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs CS 6A Fall 206 Structure and Interpretation of Computer Programs Final Solutions INSTRUCTIONS You have hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator,

More information

Introduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples

Introduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples Introduction to Typed Racket The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples Getting started Find a machine with DrRacket installed (e.g. the

More information

Racket: Modules, Contracts, Languages

Racket: Modules, Contracts, Languages Racket: Modules, Contracts, Languages Advanced Functional Programming Jean-Noël Monette November 2013 1 Today Modules are the way to structure larger programs in smaller pieces. Modules can import and

More information

Typed Scheme: Scheme with Static Types

Typed Scheme: Scheme with Static Types Typed Scheme: Scheme with Static Types Version 4.1.1 Sam Tobin-Hochstadt October 5, 2008 Typed Scheme is a Scheme-like language, with a type system that supports common Scheme programming idioms. Explicit

More information

CS 135 Winter 2018 Tutorial 8: Mutual recursion, nested lists, and local. CS 135 Winter 2018 Tutorial 8: Mutual recursion, nested lists, and local 1

CS 135 Winter 2018 Tutorial 8: Mutual recursion, nested lists, and local. CS 135 Winter 2018 Tutorial 8: Mutual recursion, nested lists, and local 1 CS 135 Winter 2018 Tutorial 8: Mutual recursion, nested lists, and local CS 135 Winter 2018 Tutorial 8: Mutual recursion, nested lists, and local 1 Goals of this tutorial You should be able to... write

More information

Module 10: Imperative Programming, Modularization, and The Future

Module 10: Imperative Programming, Modularization, and The Future Module 10: Imperative Programming, Modularization, and The Future If you have not already, make sure you Read How to Design Programs Sections 18. 1 CS 115 Module 10: Imperative Programming, Modularization,

More information

Extensible Pattern Matching

Extensible Pattern Matching Extensible Pattern Matching Sam Tobin-Hochstadt PLT @ Northeastern University IFL, September 3, 2010 Extensible Pattern Matching in an Extensible Language Sam Tobin-Hochstadt PLT @ Northeastern University

More information

Supplementary Material

Supplementary Material Supplementary Material Figure 1S: Scree plot of the 400 dimensional data. The Figure shows the 20 largest eigenvalues of the (normalized) correlation matrix sorted in decreasing order; the insert shows

More information

CSU211 Exam 2 Fall 2007

CSU211 Exam 2 Fall 2007 CSU211 Exam 2 Fall 2007 Name: Student Id (last 4 digits): Instructor s Name: Write down the answers in the space provided. You may use the usual primitives and expression forms, including those suggested

More information

Module 9: Trees. If you have not already, make sure you. Read How to Design Programs Sections 14, 15, CS 115 Module 9: Trees

Module 9: Trees. If you have not already, make sure you. Read How to Design Programs Sections 14, 15, CS 115 Module 9: Trees Module 9: Trees If you have not already, make sure you Read How to Design Programs Sections 14, 15, 16. 1 CS 115 Module 9: Trees Mathematical Expressions We are going to discuss how to represent mathematical

More information

CSCC24 Functional Programming Scheme Part 2

CSCC24 Functional Programming Scheme Part 2 CSCC24 Functional Programming Scheme Part 2 Carolyn MacLeod 1 winter 2012 1 Based on slides from Anya Tafliovich, and with many thanks to Gerald Penn and Prabhakar Ragde. 1 The Spirit of Lisp-like Languages

More information

15100 Fall 2005 Final Project

15100 Fall 2005 Final Project 15100 Fall 2005 Final Project Robby Findler & Jacob Matthews 1 Introduction to Sudoku Sudoku is a logic puzzle set on a nine by nine grid. The goal is to fill in the blank spaces in the puzzle with the

More information

CS 1102, A05 Final Exam

CS 1102, A05 Final Exam CS 1102, A05 Final Exam Name: Problem Points Score 1 35 2 30 3 35 Total You have 50 minutes to complete the problems on the following pages. There should be sufficient space provided for your answers.

More information

Functional abstraction. What is abstraction? Eating apples. Readings: HtDP, sections Language level: Intermediate Student With Lambda

Functional abstraction. What is abstraction? Eating apples. Readings: HtDP, sections Language level: Intermediate Student With Lambda Functional abstraction Readings: HtDP, sections 19-24. Language level: Intermediate Student With Lambda different order used in lecture section 24 material introduced much earlier sections 22, 23 not covered

More information

Functional abstraction

Functional abstraction Functional abstraction Readings: HtDP, sections 19-24. Language level: Intermediate Student With Lambda different order used in lecture section 24 material introduced much earlier sections 22, 23 not covered

More information

3. Area and perimeter.notebook November 13, All rectangles with area 12cm 2 have the same perimeter. True or false?

3. Area and perimeter.notebook November 13, All rectangles with area 12cm 2 have the same perimeter. True or false? All rectangles with area 12cm 2 have the same perimeter. True or false? Find the perimeter of the shape: Draw another shape with area a smaller perimeter. but with x y Write an expression for the perimeter

More information

Functional Programming. Pure Functional Programming

Functional Programming. Pure Functional Programming Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

More information

Building a system for symbolic differentiation

Building a system for symbolic differentiation Computer Science 21b Structure and Interpretation of Computer Programs Building a system for symbolic differentiation Selectors, constructors and predicates: (constant? e) Is e a constant? (variable? e)

More information

From FP to OOP. Start with data: class Posn { int x; int y; Posn(int x, int y) { this.x = x; this.y = y; } }

From FP to OOP. Start with data: class Posn { int x; int y; Posn(int x, int y) { this.x = x; this.y = y; } } From FP to OOP Start with data: ; A posn is ; (make-posn num num) (define-struct posn (x y)) class Posn { int x; int y; Posn(int x, int y) { this.x = x; this.y = y; 1 From FP to OOP Start with data: ;

More information

Class VIII Chapter 10 Visualising Solid Shapes Maths

Class VIII Chapter 10 Visualising Solid Shapes Maths Exercise 10.1 Question 1: For each of the given solid, the two views are given. Match for each solid the corresponding top and front views. The given solids, matched to their respective side view and top

More information

Local definitions and lexical scope

Local definitions and lexical scope Local definitions and lexical scope Readings: HtDP, Intermezzo 3 (Section 18). Language level: Intermediate Student CS 135 Winter 2018 09: Local definitions and lexical scope 1 Local definitions The functions

More information

Local definitions and lexical scope. Local definitions. Motivating local definitions. s(s a)(s b)(s c), where s = (a + b + c)/2.

Local definitions and lexical scope. Local definitions. Motivating local definitions. s(s a)(s b)(s c), where s = (a + b + c)/2. Local definitions and lexical scope Readings: HtDP, Intermezzo 3 (Section 18). Language level: Intermediate Student CS 135 Winter 2018 09: Local definitions and lexical scope 1 Local definitions The functions

More information

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

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives CS 6A Scheme Fall 208 Discussion 8: October 24, 208 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write

More information

CS115 - Module 9 - filter, map, and friends

CS115 - Module 9 - filter, map, and friends Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, Intermezzo 3 (Section 18); Sections 19-23. Abstraction abstraction, n. 3a.... The process of isolating properties or

More information

Rack Card Holder. Have a question or want us to do it for you? Give us a call

Rack Card Holder. Have a question or want us to do it for you? Give us a call Rack Card Holder To produce a rack card holder, please provide us with a digital layout file that looks like this: Have a question or want us to do it for you? Give us a call. 1.800.930.6040 Figure 1 Instructions

More information

Generative and accumulative recursion. What is generative recursion? Example revisited: GCD. Readings: Sections 25, 26, 27, 30, 31

Generative and accumulative recursion. What is generative recursion? Example revisited: GCD. Readings: Sections 25, 26, 27, 30, 31 Generative and accumulative recursion Readings: Sections 25, 26, 27, 30, 31 Some subsections not explicitly covered in lecture Section 27.2 technique applied to strings CS 135 Fall 2017 11: Generative

More information

CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees. CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1

CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees. CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1 CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1 Goals of this tutorial You should be able to... understand

More information

Use recursion to write a function that duplicates the following function: (def (f L) (map (lambda (x) (+ (sqr x) x)) L))

Use recursion to write a function that duplicates the following function: (def (f L) (map (lambda (x) (+ (sqr x) x)) L)) Write a function (multiply-each L n). It consumes a (listof Num) and a Num, and returns the list containing all the values in L, each multiplied by n. (multiply-each (list 2 3 5) 4) => (list 8 12 20) Write

More information

Outline. Data Definitions and Templates Syntax and Semantics Defensive Programming

Outline. Data Definitions and Templates Syntax and Semantics Defensive Programming Outline Data Definitions and Templates Syntax and Semantics Defensive Programming 1 Data Definitions Question 1: Are both of the following data definitions ok? ; A w-grade is either ; - num ; - posn ;

More information

CS1102: Adding Error Checking to Macros

CS1102: Adding Error Checking to Macros CS1102: Adding Error Checking to Macros Kathi Fisler, WPI October 8, 2004 1 Typos in State Machines The point of creating macros for state machines is to hide language details from the programmer. Ideally,

More information

Observer Templates. CS 5010 Program Design Paradigms Lesson 1.4

Observer Templates. CS 5010 Program Design Paradigms Lesson 1.4 Observer Templates CS 5010 Program Design Paradigms Lesson 1.4 Mitchell Wand, 2012-2014 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. 1 Learning Objectives

More information

Problem 1: Binary Trees: Flatten

Problem 1: Binary Trees: Flatten Problem 1: Binary Trees: Flatten Recall the data definition for binary trees: A binary-tree is either: #f (make-bt val left right) where val is a number, and left and right are binary-trees. (define-struct

More information

Generations Monograms + Monogramming Masterpieces By Bernadette Griffith Generations Software

Generations Monograms + Monogramming Masterpieces By Bernadette Griffith Generations Software Creating monograms in Generations Monograms+ is a snap. Just select one of the build in monogram templates, a True Type Font lettering style and one of the decorative borders and frames included in the

More information

CSE 341 : Programming Languages Midterm, Spring 2015

CSE 341 : Programming Languages Midterm, Spring 2015 Name: CSE 341 : Programming Languages Midterm, Spring 2015 Please do not turn the page until 12:30. Rules: Closed book, closed note, except for one side of one 8.5x11in piece of paper. Please stop promptly

More information

Lists. Readings: HtDP, sections 9 and 10. Avoid 10.3 (uses draw.ss). CS 135 Winter : Lists 1

Lists. Readings: HtDP, sections 9 and 10. Avoid 10.3 (uses draw.ss). CS 135 Winter : Lists 1 Lists Readings: HtDP, sections 9 and 10. Avoid 10.3 (uses draw.ss). CS 135 Winter 2018 05: Lists 1 Introducing lists Structures are useful for representing a fixed amount of data. But there are many circumstances

More information

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

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page. MORE SCHEME COMPUTER SCIENCE MENTORS 61A October 30 to November 3, 2017 1 What Would Scheme Print? Solutions begin on the following page. 1. What will Scheme output? Draw box-and-pointer diagrams to help

More information

LISP. Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits.

LISP. Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits. LISP Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits. From one perspective, sequences of bits can be interpreted as a code for ordinary decimal digits,

More information

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

Procedural abstraction SICP Data abstractions. The universe of procedures forsqrt. Procedural abstraction example: sqrt Data abstractions Abstractions and their variations Basic data abstractions Why data abstractions are useful Procedural abstraction Process of procedural abstraction Define formal parameters, capture process

More information

Functional Programming. Pure Functional Languages

Functional Programming. Pure Functional Languages Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure

More information

Version 5.0. Alexander Friedman and Jamie Raymond. June 6, 2010

Version 5.0. Alexander Friedman and Jamie Raymond. June 6, 2010 PLoT: Graph Plotting Version 5.0 Alexander Friedman and Jamie Raymond June 6, 2010 PLoT (a.k.a. PLTplot) provides a basic interface for producing common types of plots such as line and vector field plots

More information

Using the Shaping Tools to Modify Objects

Using the Shaping Tools to Modify Objects Using the Shaping Tools to Modify Objects In CorelDRAW, shaping commands give users a powerful means to create new shapes or manipulate current shapes by adding, subtracting, or dividing them. Shaping

More information

CS 457/557: Functional Languages

CS 457/557: Functional Languages CS 457/557: Functional Languages Lists and Algebraic Datatypes Mark P Jones Portland State University 1 Why Lists? Lists are a heavily used data structure in many functional programs Special syntax is

More information

Visual Studies Exercise.Topic08 (Architectural Paleontology) Geographic Information Systems (GIS), Part I

Visual Studies Exercise.Topic08 (Architectural Paleontology) Geographic Information Systems (GIS), Part I ARCH1291 Visual Studies II Week 8, Spring 2013 Assignment 7 GIS I Prof. Alihan Polat Visual Studies Exercise.Topic08 (Architectural Paleontology) Geographic Information Systems (GIS), Part I Medium: GIS

More information

Working with recursion. From definition to template. Readings: HtDP, sections 11, 12, 13 (Intermezzo 2).

Working with recursion. From definition to template. Readings: HtDP, sections 11, 12, 13 (Intermezzo 2). Working with recursion Readings: HtDP, sections 11, 12, 13 (Intermezzo 2). We can extend the idea of a self-referential definition to defining the natural numbers, which leads to the use of recursion in

More information

Working with recursion

Working with recursion Working with recursion Readings: HtDP, sections 11, 12, 13 (Intermezzo 2). We can extend the idea of a self-referential definition to defining the natural numbers, which leads to the use of recursion in

More information

classroomsecrets.com Reasoning and Problem Solving Geometry: Shape Sort 2D Shapes Teaching Information

classroomsecrets.com Reasoning and Problem Solving Geometry: Shape Sort 2D Shapes Teaching Information National Curriculum Objective: Mathematics Year 1: Recognise and name common 2-D shapes [for example, rectangles (including squares), circles and triangles] Differentiation: Developing Explain if the sorting

More information

Advanced Programming Handout 6. Purely Functional Data Structures: A Case Study in Functional Programming

Advanced Programming Handout 6. Purely Functional Data Structures: A Case Study in Functional Programming Advanced Programming Handout 6 Purely Functional Data Structures: A Case Study in Functional Programming Persistent vs. Ephemeral An ephemeral data structure is one for which only one version is available

More information

Model-View-Controller Architecture

Model-View-Controller Architecture Model-View-Controller Architecture CS 5010 Program Design Paradigms Bootcamp Lesson 11.3 Mitchell Wand, 2012-2015 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International

More information

Introduction to Functional Programming in Racket. CS 550 Programming Languages Jeremy Johnson

Introduction to Functional Programming in Racket. CS 550 Programming Languages Jeremy Johnson Introduction to Functional Programming in Racket CS 550 Programming Languages Jeremy Johnson 1 Objective To introduce functional programming in racket Programs are functions and their semantics involve

More information

n n Try tutorial on front page to get started! n spring13/ n Stack Overflow!

n   n Try tutorial on front page to get started! n   spring13/ n Stack Overflow! Announcements n Rainbow grades: HW1-6, Quiz1-5, Exam1 n Still grading: HW7, Quiz6, Exam2 Intro to Haskell n HW8 due today n HW9, Haskell, out tonight, due Nov. 16 th n Individual assignment n Start early!

More information

DSL Quick-Install Guide

DSL Quick-Install Guide DSL Quick-Install Guide Last Update: April 22, 2008 - 2 - Welcome and Introduction... 4 Setting Up Your DSL Modem... 5 Step 1 (Check Equipment)... 5 Step 2 (Install Inline Micro-Filters)... 5 Step 3 (ADSL

More information

Module 9: Binary trees

Module 9: Binary trees Module 9: Binary trees Readings: HtDP, Section 14 We will cover the ideas in the text using different examples and different terminology. The readings are still important as an additional source of examples.

More information

Basic Operations and Equivalent Expressions - Step-by-Step Lesson

Basic Operations and Equivalent Expressions - Step-by-Step Lesson Name Date Basic Operations and Equivalent Expressions StepbyStep Lesson Lesson 1 Simplify the expressions. 1. 4 (6x 5) 2. 3 (4 3 7x) Explanation: 1. Step 1) First see what is being asked. We have to simplify

More information

One of the main selling points of a database engine is the ability to make declarative queries---like SQL---that specify what should be done while

One of the main selling points of a database engine is the ability to make declarative queries---like SQL---that specify what should be done while 1 One of the main selling points of a database engine is the ability to make declarative queries---like SQL---that specify what should be done while leaving the engine to choose the best way of fulfilling

More information

Functional Programming - 2. Higher Order Functions

Functional Programming - 2. Higher Order Functions Functional Programming - 2 Higher Order Functions Map on a list Apply Reductions: foldr, foldl Lexical scoping with let s Functional-11, CS5314, Sp16 BGRyder 1 Higher Order Functions Functions as 1st class

More information

CS2500 Exam 2 Fall 2011

CS2500 Exam 2 Fall 2011 CS2500 Exam 2 Fall 2011 Name: Student Id (last 4 digits): Section (morning, honors or afternoon): Write down the answers in the space provided. You may use the usual primitives and expression forms, including

More information

Grade 6 Math Circles Winter 2013 Fractions

Grade 6 Math Circles Winter 2013 Fractions University of Waterloo Faculty of Mathematics Grade 6 Math Circles Winter 203 Fractions Review A fraction is how we express parts of a whole. We call the top part of a fraction the numerator, and the bottom

More information

Lesson 1 Introduction to PowerPoint

Lesson 1 Introduction to PowerPoint Lesson 1 Introduction to PowerPoint What It Is-- Presentation tool that allows you to view slides Can include text, graphics, animation, sound, video, charts, and transitions Can create handouts, speaker

More information

Principles of Programming Languages 2017W, Functional Programming

Principles of Programming Languages 2017W, Functional Programming Principles of Programming Languages 2017W, Functional Programming Assignment 3: Lisp Machine (16 points) Lisp is a language based on the lambda calculus with strict execution semantics and dynamic typing.

More information

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

System navigation. generated from the 2.0 help files. Copyright 2003 System navigation Page 1

System navigation. generated from the 2.0 help files. Copyright 2003 System navigation Page 1 System navigation generated from the 2.0 help files Copyright 2003 System navigation Page 1 .pdf created on 4/7/03 WebCTRL v2.0 Copyright 2003 Automated Logic Corporation. All rights reserved. 1150 Roberts

More information

User-defined Functions. Conditional Expressions in Scheme

User-defined Functions. Conditional Expressions in Scheme User-defined Functions The list (lambda (args (body s to a function with (args as its argument list and (body as the function body. No quotes are needed for (args or (body. (lambda (x (+ x 1 s to the increment

More information

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

cs61amt2_4 CS 61A Midterm #2 ver March 2, 1998 Exam version: A Your name login: cs61a- Discussion section number TA's name CS 61A Midterm #2 ver1.03 -- March 2, 1998 Exam version: A Your name login: cs61a- Discussion section number TA's name Look at the edge of your seat. Write your ROOM, seat row and number. Your row number

More information

Name: Class: Date: 2. I have four vertices. I have four right angles and all my sides are the same length.

Name: Class: Date: 2. I have four vertices. I have four right angles and all my sides are the same length. 1. Circle the right triangles. Use the corner of a piece of paper to check. 2. I have four vertices. I have four right angles and all my sides are the same length. What am I? 3. I have four vertices. All

More information