2. First steps Flashcards

1
Q

Function that gives the first element of a list.

A

> head [1,2,3,4]
1

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

Function that removes the first element of a list.

A

> tail [1,2,3,4,5]
[2,3,4,5]

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

Function that selects the nth element of a list.

A

> [1,2,3,4] !! 2
3

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

Function that selects the first n elements of a list.

A

> take 3 [1,2,3,4,5]
[1,2,3]

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

Function that removes the first n elements from a list.

A

> drop 3 [1,2,3,4,5]
[4,5]

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

Function that gives the length of a list.

A

> length [1,2,3,4,5]
5

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

Function that calculates the sum of a list.

A

> sum [1,2,3,4,5]
15

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

Function that calculates the product of a list.

A

> product [1,2,3,4,5]
120

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

Function that appends two lists

A

> [1,2,3] ++ [4,5]
[1,2,3,4,5]

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

Function that reverses a list.

A

> reverse [1,2,3,4,5]
[5,4,3,2,1]

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

How to put a function between it’s 2 arguments?

A

Use ` ` i.e. 6 div 3 = 2.

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

How to specify variables after they’re used?

A

the where {} operator.
i.e. a = b + c where {b = 2, c = 3}

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

How can we write comments?

A

– and {- -}

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

Function to get last element of a list.

A

> last [1,2,3,4,5]
5

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

Function to remove last element of a list.

A

> init [1,2,3,4,5]
[1,2,3,4]

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