I have this assignment:
Consider a list where every element is a nested list of length 2. The first element of each nested list is either a 0 or a 1. The second element of each nested list is some integer. An example input in Scheme is written below.
'((0 1) (1 2) (1 3) (0 4) (0 3))
For the purposes of this question, let’s call the first element of each nested list the key and the second element of the nested lists the value. Now consider a function,
count_by_cat
, that takes such a list as input and yields a two-element list where
- the first element is the sum of the values of all nested lists with 0 as the key, and
- the second element is the sum of the values of all nested lists with 1 as the key
Implement
count_by_cat
in
- (a) Racket, and
- (b) ML.
It might be helpful to create helper functions. Also do not forget about
map
andfilter
(filter
is not a built-in in ML).
I'm new to Racket and ML. I'm stuck at using accessing lists and stuff in Racket. Some help with ML would also be great.