Coding Standards through Chapter 9 apply to this lab. While the coding standards are actually for Python code, apply the spirit of the standards also to Sifflet programs—for example, use descriptive variable and function names.
The additional rule(s) of Lab 8 also apply.
You'll need to use Sifflet for each of these problems (probably on merlin.iue.edu).
Define a Sifflet function with two arguments, x and ys, where ys is a list of numbers and x is a number. The function's value is how many times x occurs as an element in ys.
Examples:
If x = 777, then for ys = [777, 888, 777, 999], the answer is 2; but for ys = [], the answer is 0.
If x = 50505 and ys = [1, 50505, 2, 50505, 3, 50505, 4, 50505], the answer should be 4.
Hints: The function needs to be recursive. How many times does x occur in []? If ys is non-empty, then is x the head, and where else do you need to count it?
Define a Sifflet function with one argument, a list of numbers. The function returns the list formed by adding one to every number in the given list. In other words, it maps the function add1 over the list of numbers. For example, given [2, 7, 5, 11], the function should return [3, 8, 6, 12].
Hints: This one is recursive, too. What is the result, if the list is []? If it's not empty, what should you do to its head? What should you do to its tail?
Test your solution of problem 1 (counting occurrences) with the values x = 17 and ys = [15, 17, 7, 17, 27, 17], capture a screenshot.
Test your solution of problem 2 (adding one) with the list [5, 7, 9, 4, 15]. Capture a screenshot of your test.
Turn in both screenshots through Oncourse Assignments.
Total: 9 points