4.12 Functional Programming Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is the Domain?

A

1) The Domain is the set from which the functions input values are chosen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the Co-Domain?

A

1) The Co-Domain is the set from which the functions output values are chosen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What type of object is a function?

A

1) A function is a first-class object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the characteristics of a First-Class Object?

A

1) Appear in Expressions
2) Assigned to a variable
3) Assigned as arguments
4) Returned in function calls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Function Application?

A

1) Function Application occurs when a function is applied to its arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the Composition of Functions?

A

1) The combination of two functions to get a new function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a High-Order Function?

A

1) A higher-order function takes a function as an argument or returns a function as a result or does both

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a Map?

A

1) A Map takes in two arguments as inputs
- A Function
- A List

2) The Function is applied to each item of the list to produce a function output with new list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the result of the following:

Map (5) [2,5,7,8,9]

A

[10,25,35,40,45]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a Filter?

A

1) A Filter takes in two arguments as inputs
- A predicate (to define a boolean condition)
- A-List

2) A Function is applied to each item in the list and it returns a new list of each item that matches the predicate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the result of the following:

Filter (>6) [2,5,6,8,9]

A

[8,9]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is A Fold (Recursive function)

A

1) Applies a function to each item of a list to produce a single value
2) An initial value is also supplied which will be recursively combined with the next item and so on

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the result of the following:

Fold (+)0[2,3,4,5]

A

[2,5,9,14]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How is a list represented?

A

1) A List is represented as a concatenation of a head and a tail

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How are the head and tail split up in a list?

A

[a,[b,c,d,e]]
a = head
b,c,d,e = tail of a list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Can a list be empty?

A

Yes

17
Q

Explain what the following operation does?

tail(list)

A

Returns a new list containing all but the first element of the original list

18
Q

Explain what the following does?

head(list)

A

Returns the first element in a list

19
Q

Explain what the following does?

empty(list)

A

Returns True if a list is empty otherwise False

20
Q

Explain what the following does?

length(list)

A

Returns the number of elements in a list

21
Q

Explain what the following does?

‘ : ‘ list constructor

A

Adds the items to the beginning of a list

22
Q

Explain what the following does?

prepend

A

Adds an item to the start of the list

23
Q

Explain what the following does?

append

A

Adds an item to the end of the list

24
Q

What type of list is this?

[]

A

Empty List