Identifier: SiffList
Prerequisites: SiffNum, SiffCond
Building and taking apart lists in Sifflet
Students should be able to:
head, tail, null, and :Sifflet Tutorial, lessons 6 and 7.
See Oncourse Module 8.
Define Sifflet functions:
[["a", "b"], ["c", "d"]], the value should be "a"."a", the value should be ["a", "a", "a"].[[10]].Solutions for some of these:
Coding Standards through Chapter 5 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.
In addition, although Sifflet allows you to create function and variable names that contain spaces, you should not do so, because such names are confusing. (If your function is named function a and your parameter is named b c, then when you see function a b c doesn't it look like a function with three parameters?)
You'll need to use Sifflet for each of these problems.
Define a Sifflet function with one argument, a list, which returns the fourth element of the list (counting the head as position one).
For example, given the list ["a", "b", "c", "d", "e"], the function should return "d". It is an error if the list contains fewer than four elements. (It is not necessary for your function to check that the list has four or more elements—just let the error happen if you wish.)
Test with any list having four or more elements, and capture a screenshot.
Hint: Non-recursive. Use the head and tail functions.
Define a Sifflet function with two arguments, an integer n and an integer d. The function returns a list with two elements: the integer quotient of n divided by d, and the integer remainder of the same.
Test with the values n = 23 and d = 7. Capture a screenshot.
Hint: Non-recursive. Use cons (:), the empty list (the literal []), div, and mod.