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

Size: px
Start display at page:

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

Transcription

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

2 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 assignment on Odyssey. CS 135 Fall 2018 Final Exam Review 2

3 ALFs - digits->num Without using explicit recursion, write a function called digits->num that consumes a non-empty list of digits and produces the number those digits form. Include a contract. Try to do it without reversing the list. (digits->num (5)) 5 (digits->num ( )) CS 135 Fall 2018 Final Exam Review 3

4 ALFs - count Without using explicit recursion, write a function called count that consumes 2 arguments, of which the second one is a list. It produces the number of times the first argument occurs in the list. (count cat (3 "cat" 11)) 0 (count cat ("cat" cat 4 cat 6)) 2 CS 135 Fall 2018 Final Exam Review 4

5 ALFs - count-chars Without using explicit recursion, write a function called count-chars that consumes a Char and a (listof Any). It should count the number of occurrences of the character in all the strings in the list. You may use count that you wrote in the previous question. (count-chars #\a (a "Aardvark" #\a ("abba" 12) "hagrid!?")) 3 CS 135 Fall 2018 Final Exam Review 5

6 Nested List - count-chars/nested Write a function called count-chars/nested that consumes a Char and a Nest-List-Any. It should count the number of occurrences of the character in all the strings in the nested list. You can use explicit recursion. You may also use count that you wrote previously. (count-chars/nested #\a (a "Aardvark" (#\a "hag" "ah") "at" ("doggo"))) 5 Recall the data definition for a nested list: ;; A (Nest-List-Any) is one of: ;; * empty ;; * (cons Any Nest-List-Any) ;; * (cons Nest-List-Any Nest-List-Any) CS 135 Fall 2018 Final Exam Review 6

7 Graphs - delete-node Write a function delete-node that consumes a Node v and a Graph g and produces the graph with v removed. If v does not exist in g, the same graph is produced. (define g1 ((A (B C F)) (B ()) (C (A B)) (D (A C F)) (E (A B C)) (F (A))) (define g1 ((A (B C F)) (B ()) (C (A B)) (D (A C F)) (E (A B C)) (F (A))) (delete-node C g1) ((A (B F)) (B ()) (D (A F)) (E (A B)) (F (A))) CS 135 Fall 2018 Final Exam Review 7

8 Stepping Lambda: Example Given that the following definition has been processed in the Intermediate Student with Lambda language: (define fun (lambda (x y) (lambda (y z) (lambda (z) (+ x y z))))) Produce a step-by-step evaluation of the following program: (((fun 1 2) 3 4) 5) CS 135 Fall 2018 Final Exam Review 8

9 Stepping Lambda: Example ((((lambda (x y) (lambda (y z) (lambda (z) (+ x y z)))) 1 2) 3 4) 5) CS 135 Fall 2018 Final Exam Review 9

10 Stepping Lambda: Example ((((lambda (x y) (lambda (y z) (lambda (z) (+ x y z)))) 1 2) 3 4) 5) (((lambda (y z) (lambda (z) (+ 1 y z))) 3 4) 5) CS 135 Fall 2018 Final Exam Review 10

11 Stepping Lambda: Example ((((lambda (x y) (lambda (y z) (lambda (z) (+ x y z)))) 1 2) 3 4) 5) (((lambda (y z) (lambda (z) (+ 1 y z))) 3 4) 5) ((lambda (z) (+ 1 3 z)) 5) CS 135 Fall 2018 Final Exam Review 11

12 Stepping Lambda: Example ((((lambda (x y) (lambda (y z) (lambda (z) (+ x y z)))) 1 2) 3 4) 5) (((lambda (y z) (lambda (z) (+ 1 y z))) 3 4) 5) ((lambda (z) (+ 1 3 z)) 5) ( ) CS 135 Fall 2018 Final Exam Review 12

13 Stepping Lambda: Example ((((lambda (x y) (lambda (y z) (lambda (z) (+ x y z)))) 1 2) 3 4) 5) (((lambda (y z) (lambda (z) (+ 1 y z))) 3 4) 5) ((lambda (z) (+ 1 3 z)) 5) ( ) 9 CS 135 Fall 2018 Final Exam Review 13

14 BTs ;; An Integer Binary Tree (IntBT) is one of: ;; * empty ;; * an IntNode (define-struct int-node (key left right)) ;; An IntNode is a (make-int-node Int IntBT IntBT) Note this is different from a BST! CS 135 Fall 2018 Final Exam Review 14

15 BTs - min-key Write a function, min-key that consumes a non-empty IntBT and produces the minimum key in that tree. 3 (define b1 (make-int-node (make-int-node 900 empty (make-int-node 200 empty empty)) (make-int-node 6 (make-int-node 8 empty empty) (make-int-node 10 (make-int-node 2 empty empty) empty)))) (min-key b1) CS 135 Fall 2018 Final Exam Review 15

16 Which of the following was one of Grace Hopper s achievements? A) Proof that the Halting Problem is undecidable B) Design for the Analytical Engine C) Creation of the first compiler D) Axiomatization of geometry E) Development of FORTRAN CS 135 Fall 2018 Final Exam Review 16

17 Mutual recursion - Extended-Factor-Tree For this example, we are going to build an extended factor tree for a positive natural number. The extended factor tree of a number n has the number itself as the root node and all of its factors between 2 and n-1, in the extended factor tree form. Write build-tree that consumes a natural number n and produces the extended factor tree form of n. ;; An extended-factor-tree is a (list Nat (listof extended-factor-tree)) 12 (define sample-tree (list 12 (list (list 2 empty) (list 3 empty) (list 4 (list (list 2 empty))) (list 6 (list (list 2 empty) (list 3 empty)))))) CS 135 Fall 2018 Final Exam Review 17

18 Who developed the Lisp programming language? A) John von Neumann B) Alonzo Church C) Kurt Gödel D) Grace Hopper E) John McCarthy CS 135 Fall 2018 Final Exam Review 18

19 Generative Recursion: group-equal-elems Write a function group-equal-elems that consumes an arbitrary list lst and rearranges the elements in lst so that identical elements are all grouped together. The rearranged elements should appear in the the same relative order as the first unique occurrence of each value in the consumed lst when read from left to right. (group-equal-elems (list )) (list ) CS 135 Fall 2018 Final Exam Review 19

20 Generative Recursion: group-equal-elems ;; group-equal-elems: (listof X) (listof X) (define (group-equal-elems lst) (cond [(empty? lst) empty] [else (local [(define matches (filter (lambda (x) (equal? x (first lst))) lst)) (define others (filter (lambda (x) (not (equal? x (first lst)))) lst))] (append matches (group-equal-elems others)))])) CS 135 Fall 2018 Final Exam Review 20

21 What question do you want next? A) Abstract List Function Problems B) Graph Problems C) Tree Problems D) Mutual Recursion Problems E) Other Problems CS 135 Fall 2018 Final Exam Review 21

22 Generative recursion - count-uniq Write a function count-uniq that consumes a list and produces the number of unique elements in it. Do not use an accumulator. (count-uniq (a a 1 b 1 2)) 4 (count-uniq (a b c)) 3 (count-uniq ()) 0 CS 135 Fall 2018 Final Exam Review 22

23 ALFs: take-last Write a function take-last that consumes a list and a natural number n, and produces a list containing only the last n elements of the list, or the entire list if it contains fewer than n elements. (take-last empty 1) empty (take-last (b a s e) 2) (s e) (take-last (list 1 1 2) 4) (list 1 1 2) CS 135 Fall 2018 Final Exam Review 23

24 ALFs: take-last ;; take-last: (listof X) Nat (listof X) (define (take-last lst n) (foldr (lambda (itm rr) (cond [(= n (length rr)) rr] [else (cons itm rr)])) empty lst)) CS 135 Fall 2018 Final Exam Review 24

25 ALFs: take-last The previous solution calls length over and over again, which makes it very inefficient. Here are some additional approaches to the problem. As an exercise, you should try implementing them in racket: Use foldr to go over the list starting from the back. We keep extra info in our recursive result to tell us how long the current list is. This way, we don t need to compute length over and over again. Reverse the list, take the first n elements, then reverse our answer. We only call reverse twice in this solution. Zip each element with an index (0 referring to the last element), then we cut the list from the front until the index is smaller or equal to n. In the end, remove the index with a map. CS 135 Fall 2018 Final Exam Review 25

26 Length of a Longest Path Recall from lectures that a sequence of nodes v 1, v 2,..., v k is a path of length k 1 if (v 1, v 2 ), (v 2, v 3 ),..., (v k 1, v k ) are all edges. Directed graphs without cycles are called directed acyclic graphs (DAGs). Write a function max-path-length that consumes a DAG dag and produces the length of a longest path in dag. If dag has no paths, produce 0. CS 135 Fall 2018 Final Exam Review 26

27 ;; max-path-length/list: (listof Node) Graph Nat (define (max-path-length/list l-nds dag) (cond [(empty? l-nds) 0] [else (local [(define nbrs (neighbours (first l-nds) dag))] (cond [(empty? nbrs) (max-path-length/list (rest l-nds) dag)] [else (max (add1 (max-path-length/list nbrs dag)) (max-path-length/list (rest l-nds) dag))]))])) ;; max-path-length: Graph Nat (define (max-path-length dag) (max-path-length/list (map first dag) dag)) CS 135 Fall 2018 Final Exam Review 27

28 BSTs - keys-in-range Write a function, keys-in-range that consumes 2 numbers, lo and hi, and a BST. It produces a list of all the keys in the BST that are between lo and hi inclusive. You should not try to convert the entire tree into a list first. garbage 3 (keys-in-range 2 7 empty) empty (keys-in-range 2 7 b1) ( ) 1 6 (keys-in-range 5 2 b1) empty CS 135 Fall 2018 Final Exam Review 28

29 Stepping Local When renaming local definitions append 0 if possible, or else 1, 2, etc. Do not recopy any line that is already in simplest form. (define x 5) (define y 10) (define (my-fn a b) (local [(define x (+ a b)) (define y (+ x (local [(define x 20)] x)))] (list x y))) (my-fn x y) CS 135 Fall 2018 Final Exam Review 29

30 ALFs - build-x Write build-x that consumes an odd natural number n and produces a table as a (listof (listof Nat)) that contains 1s on the 2 diagonals and 0s everywhere else. Do not use explicit recursion. (ones-on-diagonal 1) (list (list 1)) (ones-on-diagonal 3) (list (list 1 0 1) (list 0 1 0) (list 1 0 1))) CS 135 Fall 2018 Final Exam Review 30

31 Mutual recursion - Tournament For this example, we are going to use trees to model the results of a tournament. (define-struct tournament (winner round)) ;; A Tournament is a (make-tournament Str Round) ;; requires: winner is the name of the player with the best time ;; in the topmost round ;; A Round is a (listof Player) (define-struct player (name time last-round)) ;; A Player is a (make-player Str Num Round) ;; requires: time > 0 ;; name is the player with the best time in the topmost ;; round of last-round if it is non-empty CS 135 Fall 2018 Final Exam Review 31

32 Jesse Ben 12.3 Bill 16.9 Jesse 12.1 Anne 13.1 Ben 11 Bill 15.1 Yao 15.8 Jason 18.3 Jesse 19.9 Jimmy 9999 (define cs135-cup (make-tournament "Jesse" (list (make-player "Ben" 12.3 (list (make-player "Anne" 13.1 empty) (make-player "Ben" 11 empty))) (make-player "Bill" 16.9 (list (make-player "Bill" 15.1 empty) (make-player "Yao" 15.8 empty) (make-player "Jason" 18.3 empty))) (make-player "Jesse" 12.1 (list (make-player "Jesse" 19.9 empty) (make-player "Jimmy" 9999 empty)))))) CS 135 Fall 2018 Final Exam Review 32

33 Mutual recursion - Templates Write a template function for each of Tournament, Round and Player. (define-struct tournament (winner round)) ;; A Tournament is a (make-tournament Str Round) ;; requires: winner is the name of the player with the best time ;; in the topmost round ;; A Round is a (listof Player) (define-struct player (name time last-round)) ;; A Player is a (make-player Str Num Round) ;; requires: time > 0 ;; name is the player with the best time in the topmost ;; round of last-round if it is non-empty CS 135 Fall 2018 Final Exam Review 33

34 Mutual recursion - new-record Here s a structure we will use to store information about a record: (define-struct record (name time)) ;; A Record is a (make-record Str Num) ;; requires: time > 0 A player makes a new record if they have a faster time than the current record. Using your templates, write a function new-record that consumes a current record and a Tournament. It should produce a Record structure with the name and time of the player in the tournament who has the new record. If no one in the tournament had a faster time than the current record, produce false. You may assume that all times in the tournament are unique. (new-record (make-record "Bill" 11.2) cs135-cup) (make-record "Ben" 11) (new-record (make-record "Karen" 3.1) cs135-cup) false CS 135 Fall 2018 Final Exam Review 34

35 Stepping Lambda Recall that the rule for evaluating anonymous lambda expression is ((lambda (x1... xn) exp) v1... vn) exp where exp is exp with all occurrences of x1 replaced by v1, all occurrences of x2 replaced by v2, and so on. CS 135 Fall 2018 Final Exam Review 35

36 Stepping Local An expression of the form (local [(define x1 exp1)... (define xn expn)] bodyexp) is handled as follows. x1 is replaced with a fresh identifier (call it x1 new) everywhere it s used in the local expression. The same thing is done with x2 through xn. The definitions (define x1 new exp1)... (define xn new expn) are then lifted out (all at once) to the top level of the program, preserving their order. CS 135 Fall 2018 Final Exam Review 36

37 Stepping Local When all the rewritten definitions have been lifted out, what remains looks like (local [] bodyexp ), where bodyexp is the rewritten version of bodyexp. This is just replaced with bodyexp. All of this is a single step. (local [(define x1 exp1)... (define xn expn)] bodyexp) (define x1 0 exp1 )... (define xn 0 expn ) bodyexp CS 135 Fall 2018 Final Exam Review 37

38 Accumulative and Generative Recursion Accumulative Recursion All parameters in the recursive call are either unchanged or one step closer to the base case (as with pure structural recursion), plus one or more parameters that accumulate partial answers Accumulators are usually produced in the base case(s) directly, or manipulated before being produced In the recursive call, it does not matter how complicated the code is to update an accumulator, as long as it adds on to the partial answer CS 135 Fall 2018 Final Exam Review 38

39 Generative Recursion A parameter is considered generative if: It is changed in the recursive call without a clear base case It doesn t get one step closer to the base case in the recursive call, according to the data definition It is not an accumulator, and thus isn t produced in the base case Examples of generative recursive calls: (collatz (+ 1 ( 3 n))) (foo (not bool)) (foo (rest (rest (rest lst)))) (foo (remove elem lst)) If in any recursive call of a function, there is at least one parameter that satisfies the conditions above, regardless of how the other parameters are changing, the function uses generative recursion. CS 135 Fall 2018 Final Exam Review 39

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Types of recursion. Structural vs. general recursion. Pure structural recursion. Readings: none. In this module: learn to use accumulative recursion Types of recursion Readings: none. In this module: learn to use accumulative recursion learn to recognize generative recursion CS 135 Fall 2018 07: Types of recursion 1 Structural vs. general recursion

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

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

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

Module 8: Binary trees

Module 8: Binary trees Module 8: 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

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

Assignment: 7. Due: Language level: Allowed recursion:

Assignment: 7. Due: Language level: Allowed recursion: Assignment: 7 Due: Language level: Allowed recursion: CS 135 Winter 2018 Graham, Nijjar Tuesday, March 13th, 2018 9:00pm Beginning Student with List Abbreviations Pure Structural and Structural Recursion

More information

CS115 - Module 4 - Compound data: structures

CS115 - Module 4 - Compound data: structures Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, sections 6-7, omitting 6.2, 6.6, 6.7, and 7.4. Compound data It often comes up that we wish to join several pieces

More information

CS115 - Module 8 - Binary trees

CS115 - Module 8 - Binary trees Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, Section 14. Binary arithmetic expressions Operators such as +,,, and take two arguments, so we call them binary operators.

More information

Types of recursion. Readings: none. In this module: a glimpse of non-structural recursion. CS 135 Winter : Types of recursion 1

Types of recursion. Readings: none. In this module: a glimpse of non-structural recursion. CS 135 Winter : Types of recursion 1 Types of recursion Readings: none. In this module: a glimpse of non-structural recursion CS 135 Winter 2018 07: Types of recursion 1 Structural vs. general recursion All of the recursion we have done to

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

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

Local defini1ons. Func1on mul1ples- of

Local defini1ons. Func1on mul1ples- of Local defini1ons The func1ons and special forms we ve seen so far can be arbitrarily nested except define and check- expect. So far, defini.ons have to be made at the top level, outside any expression.

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 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

Wellesley College CS251 Programming Languages Spring, 2000 FINAL EXAM REVIEW PROBLEM SOLUTIONS

Wellesley College CS251 Programming Languages Spring, 2000 FINAL EXAM REVIEW PROBLEM SOLUTIONS Wellesley College CS251 Programming Languages Spring, 2000 FINAL EXAM REVIEW PROBLEM SOLUTIONS This document contains solutions to the problems on the final exam review problems posted earlier except for

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

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

Computer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs. Lexical addressing Computer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs Lexical addressing The difference between a interpreter and a compiler is really two points on a spectrum of possible

More information

Module 3: New types of data

Module 3: New types of data Module 3: New types of data Readings: Sections 4 and 5 of HtDP. A Racket program applies functions to values to compute new values. These new values may in turn be supplied as arguments to other functions.

More information

Homework 6: Higher-Order Procedures Due: 11:59 PM, Oct 16, 2018

Homework 6: Higher-Order Procedures Due: 11:59 PM, Oct 16, 2018 Integrated Introduction to Computer Science Klein Homework 6: Higher-Order Procedures Due: 11:59 PM, Oct 16, 2018 Contents 1 Fun with map (Practice) 2 2 Unfold (Practice) 3 3 Map2 3 4 Fold 4 5 All You

More information

CSC 533: Programming Languages. Spring 2015

CSC 533: Programming Languages. Spring 2015 CSC 533: Programming Languages Spring 2015 Functional programming LISP & Scheme S-expressions: atoms, lists functional expressions, evaluation, define primitive functions: arithmetic, predicate, symbolic,

More information

A brief tour of history

A brief tour of history Introducing Racket λ A brief tour of history We wanted a language that allowed symbolic manipulation Scheme The key to understanding LISP is understanding S-Expressions Racket List of either atoms or

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

CMSC 330: Organization of Programming Languages. OCaml Higher Order Functions

CMSC 330: Organization of Programming Languages. OCaml Higher Order Functions CMSC 330: Organization of Programming Languages OCaml Higher Order Functions CMSC330 Fall 2017 1 Anonymous Functions Recall code blocks in Ruby (1..10).each { x print x } Here, we can think of { x print

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

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

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Midterm CSE 21 Fall 2012

Midterm CSE 21 Fall 2012 Signature Name Student ID Midterm CSE 21 Fall 2012 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 _ (20 points) _ (15 points) _ (21 points) _ (13 points) _ (9 points) _ (7 points) Total _ (85 points) (80 points

More information

Functional Programming and Haskell

Functional Programming and Haskell Functional Programming and Haskell Tim Dawborn University of Sydney, Australia School of Information Technologies Tim Dawborn Functional Programming and Haskell 1/22 What are Programming Paradigms? A programming

More information

Style and Submission Guide

Style and Submission Guide Style and Submission Guide 1 Assignment Style Guidelines The code you submit for assignments, as with all code you write, can be made more readable and useful by paying attention to style. This includes

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

Organization of Programming Languages CS3200/5200N. Lecture 11

Organization of Programming Languages CS3200/5200N. Lecture 11 Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages

More information

Lists of Lists. CS 5010 Program Design Paradigms Bootcamp Lesson 5.3

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

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

LECTURE 16. Functional Programming

LECTURE 16. Functional Programming LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative

More information

CS 342 Lecture 7 Syntax Abstraction By: Hridesh Rajan

CS 342 Lecture 7 Syntax Abstraction By: Hridesh Rajan CS 342 Lecture 7 Syntax Abstraction By: Hridesh Rajan 1 Reading SICP, page 11-19, Section 1.1.6 Little Schemer, Chapter 2 2 The Idea of Syntax Abstraction Problem. Often programming tasks are repetitive,

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 16: Functional Programming Zheng (Eddy Zhang Rutgers University April 2, 2018 Review: Computation Paradigms Functional: Composition of operations on data.

More information

Lambda the Ultimate. Corky Cartwright Vivek Sarkar Department of Computer Science Rice University

Lambda the Ultimate. Corky Cartwright Vivek Sarkar Department of Computer Science Rice University Lambda the Ultimate Corky Cartwright Vivek Sarkar Department of Computer Science Rice University 1 Function filter2: variant of filter1 function from last lecture ;; filter2 : test lon -> lon ;; to construct

More information

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures Dan Grossman Fall 2014 Hi! I m not Hal J I love this stuff and have taught

More information

Scheme as implemented by Racket

Scheme as implemented by Racket Scheme as implemented by Racket (Simple view:) Racket is a version of Scheme. (Full view:) Racket is a platform for implementing and using many languages, and Scheme is one of those that come out of the

More information

Homework 6: Higher-Order Procedures Due: 10:00 PM, Oct 17, 2017

Homework 6: Higher-Order Procedures Due: 10:00 PM, Oct 17, 2017 Integrated Introduction to Computer Science Hughes Homework 6: Higher-Order Procedures Due: 10:00 PM, Oct 17, 2017 Contents 1 Fun with map (Practice) 2 2 Unfold (Practice) 3 3 Map2 3 4 Fold 4 5 All You

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

CS61A Notes 02b Fake Plastic Trees. 2. (cons ((1 a) (2 o)) (3 g)) 3. (list ((1 a) (2 o)) (3 g)) 4. (append ((1 a) (2 o)) (3 g))

CS61A Notes 02b Fake Plastic Trees. 2. (cons ((1 a) (2 o)) (3 g)) 3. (list ((1 a) (2 o)) (3 g)) 4. (append ((1 a) (2 o)) (3 g)) CS61A Notes 02b Fake Plastic Trees Box and Pointer Diagrams QUESTIONS: Evaluate the following, and draw a box-and-pointer diagram for each. (Hint: It may be easier to draw the box-and-pointer diagram first.)

More information

A Third Look At ML. Chapter Nine Modern Programming Languages, 2nd ed. 1

A Third Look At ML. Chapter Nine Modern Programming Languages, 2nd ed. 1 A Third Look At ML Chapter Nine Modern Programming Languages, 2nd ed. 1 Outline More pattern matching Function values and anonymous functions Higher-order functions and currying Predefined higher-order

More information

Lists of Lists. CS 5010 Program Design Paradigms Bootcamp Lesson 6.5

Lists of Lists. CS 5010 Program Design Paradigms Bootcamp Lesson 6.5 Lists of Lists CS 5010 Program Design Paradigms Bootcamp Lesson 6.5 Mitchell Wand, 2012-2015 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. 1 Learning

More information

Module 4: Compound data: structures

Module 4: Compound data: structures Module 4: Compound data: structures Readings: Sections 6 and 7 of HtDP. Sections 6.2, 6.6, 6.7, 7.4, and 10.3 are optional readings; they use the obsolete draw.ss teachpack. The teachpacks image.ss and

More information

CMSC 330: Organization of Programming Languages. OCaml Higher Order Functions

CMSC 330: Organization of Programming Languages. OCaml Higher Order Functions CMSC 330: Organization of Programming Languages OCaml Higher Order Functions CMSC 330 - Summer 2017 1 Anonymous Functions Recall code blocks in Ruby (1..10).each { x print x } Here, we can think of { x

More information

Processadors de Llenguatge II. Functional Paradigm. Pratt A.7 Robert Harper s SML tutorial (Sec II)

Processadors de Llenguatge II. Functional Paradigm. Pratt A.7 Robert Harper s SML tutorial (Sec II) Processadors de Llenguatge II Functional Paradigm Pratt A.7 Robert Harper s SML tutorial (Sec II) Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra Paradigm Shift Imperative Paradigm State Machine

More information

CS115 - Module 3 - Booleans, Conditionals, and Symbols

CS115 - Module 3 - Booleans, Conditionals, and Symbols Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, sections 4-5 Booleans (Bool) , and = are new functions, each of which produces a boolean value (Bool). (< 4 6)

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

CMSC 330: Organization of Programming Languages. OCaml Higher Order Functions

CMSC 330: Organization of Programming Languages. OCaml Higher Order Functions CMSC 330: Organization of Programming Languages OCaml Higher Order Functions CMSC 330 - Spring 2017 1 Anonymous Functions Recall code blocks in Ruby (1..10).each { x print x } Here, we can think of { x

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 15: Review and Functional Programming Zheng (Eddy) Zhang Rutgers University March 19, 2018 Class Information Midterm exam forum open in Sakai. HW4 and

More information

YOUR NAME PLEASE: *** SOLUTIONS ***

YOUR NAME PLEASE: *** SOLUTIONS *** YOUR NAME PLEASE: *** SOLUTIONS *** Computer Science 201b SAMPLE Exam 1 SOLUTIONS February 15, 2015 Closed book and closed notes. No electronic devices. Show ALL work you want graded on the test itself.

More information

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018 CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018 Typical workflow concrete syntax (string) "(fn x => x + x) 4" Parsing Possible errors / warnings

More information

MoreIntro_annotated.v. MoreIntro_annotated.v. Printed by Zach Tatlock. Oct 04, 16 21:55 Page 1/10

MoreIntro_annotated.v. MoreIntro_annotated.v. Printed by Zach Tatlock. Oct 04, 16 21:55 Page 1/10 Oct 04, 16 21:55 Page 1/10 * Lecture 02 Infer some type arguments automatically. Set Implicit Arguments. Note that the type constructor for functions (arrow " >") associates to the right: A > B > C = A

More information

CSE 341: Programming Languages

CSE 341: Programming Languages CSE 341: Programming Languages Autumn 2005 Lecture 10 Mutual Recursion, Equivalence, and Syntactic Sugar CSE 341 Autumn 2005, Lecture 10 1 Mutual Recursion You ve already seen how multiple functions can

More information

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

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015 SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

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

Lecture 4: Higher Order Functions

Lecture 4: Higher Order Functions Lecture 4: Higher Order Functions Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense September 26, 2017 HIGHER ORDER FUNCTIONS The order of a function

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

CSE341 Spring 2016, Final Examination June 6, 2016

CSE341 Spring 2016, Final Examination June 6, 2016 CSE341 Spring 2016, Final Examination June 6, 2016 Please do not turn the page until 8:30. Rules: The exam is closed-book, closed-note, etc. except for both sides of one 8.5x11in piece of paper. Please

More information

Mini-ML. CS 502 Lecture 2 8/28/08

Mini-ML. CS 502 Lecture 2 8/28/08 Mini-ML CS 502 Lecture 2 8/28/08 ML This course focuses on compilation techniques for functional languages Programs expressed in Standard ML Mini-ML (the source language) is an expressive core subset of

More information

Functions that return lists

Functions that return lists 342 Chapter 23 Functions that return lists If you did exercises 22.5.15 or 22.5.16, you ve already written some functions that return lists, but only in a very simple way: adding one new element to the

More information

(Provisional) Lecture 08: List recursion and recursive diagrams 10:00 AM, Sep 22, 2017

(Provisional) Lecture 08: List recursion and recursive diagrams 10:00 AM, Sep 22, 2017 Integrated Introduction to Computer Science Hughes (Provisional) Lecture 08: List recursion and recursive diagrams 10:00 AM, Sep 22, 2017 Contents 1 Announcements 1 2 Evaluation Correction 1 3 Lists 2

More information

CS 242. Fundamentals. Reading: See last slide

CS 242. Fundamentals. Reading: See last slide CS 242 Fundamentals Reading: See last slide Syntax and Semantics of Programs Syntax The symbols used to write a program Semantics The actions that occur when a program is executed Programming language

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

(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

Introduction to Functional Programming in Haskell 1 / 56

Introduction to Functional Programming in Haskell 1 / 56 Introduction to Functional Programming in Haskell 1 / 56 Outline Why learn functional programming? The essence of functional programming What is a function? Equational reasoning First-order vs. higher-order

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

Module 4: Compound data: structures

Module 4: Compound data: structures Module 4: Compound data: structures Readings: Sections 6 and 7 of HtDP. Sections 6.2, 6.6, 6.7, 7.4, and 10.3 are optional reading; they use the obsolete draw.ss teachpack. The teachpacks image.ss and

More information

CONCEPTS OF PROGRAMMING LANGUAGES Solutions for Mid-Term Examination

CONCEPTS OF PROGRAMMING LANGUAGES Solutions for Mid-Term Examination COMPUTER SCIENCE 320 CONCEPTS OF PROGRAMMING LANGUAGES Solutions for Mid-Term Examination FRIDAY, MARCH 3, 2006 Problem 1. [25 pts.] A special form is an expression that is not evaluated according to the

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

Functional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur

Functional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur Functional Programming and λ Calculus Amey Karkare Dept of CSE, IIT Kanpur 0 Software Development Challenges Growing size and complexity of modern computer programs Complicated architectures Massively

More information

CSE413 Midterm. Question Max Points Total 100

CSE413 Midterm. Question Max Points Total 100 CSE413 Midterm 05 November 2007 Name Student ID Answer all questions; show your work. You may use: 1. The Scheme language definition. 2. One 8.5 * 11 piece of paper with handwritten notes Other items,

More information

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

Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003 Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003 CS 314, LS, LTM: Functional Programming 1 Scheme A program is an expression to be evaluated (in

More information

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING Friday 20 th December 2013 14:30 to 16:30 INSTRUCTIONS TO CANDIDATES 1.

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and

More information

Assignment 2. Advanced Functional Programming, 2017 (Avancerad funktionell programmering, 2017) due 4 December 2017, 23:59

Assignment 2. Advanced Functional Programming, 2017 (Avancerad funktionell programmering, 2017) due 4 December 2017, 23:59 Assignment Advanced Functional Programming, 017 (Avancerad funktionell programmering, 017) due 4 December 017, :59 1 Targeted Property Based Testing Magic (magic.erl, 4 points) The instructions for this

More information

CS 275 Name Final Exam Solutions December 16, 2016

CS 275 Name Final Exam Solutions December 16, 2016 CS 275 Name Final Exam Solutions December 16, 2016 You may assume that atom? is a primitive procedure; you don t need to define it. Other helper functions that aren t a standard part of Scheme you need

More information

Functional Programming. Big Picture. Design of Programming Languages

Functional Programming. Big Picture. Design of Programming Languages Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

More information

Introduction to Programming, Aug-Dec 2006

Introduction to Programming, Aug-Dec 2006 Introduction to Programming, Aug-Dec 2006 Lecture 3, Friday 11 Aug 2006 Lists... We can implicitly decompose a list into its head and tail by providing a pattern with two variables to denote the two components

More information