2. First steps Flashcards
Function that gives the first element of a list.
> head [1,2,3,4]
1
Function that removes the first element of a list.
> tail [1,2,3,4,5]
[2,3,4,5]
Function that selects the nth element of a list.
> [1,2,3,4] !! 2
3
Function that selects the first n elements of a list.
> take 3 [1,2,3,4,5]
[1,2,3]
Function that removes the first n elements from a list.
> drop 3 [1,2,3,4,5]
[4,5]
Function that gives the length of a list.
> length [1,2,3,4,5]
5
Function that calculates the sum of a list.
> sum [1,2,3,4,5]
15
Function that calculates the product of a list.
> product [1,2,3,4,5]
120
Function that appends two lists
> [1,2,3] ++ [4,5]
[1,2,3,4,5]
Function that reverses a list.
> reverse [1,2,3,4,5]
[5,4,3,2,1]
How to put a function between it’s 2 arguments?
Use ` ` i.e. 6 div
3 = 2.
How to specify variables after they’re used?
the where {} operator.
i.e. a = b + c where {b = 2, c = 3}
How can we write comments?
– and {- -}
Function to get last element of a list.
> last [1,2,3,4,5]
5
Function to remove last element of a list.
> init [1,2,3,4,5]
[1,2,3,4]