CIS 343

Kawa Scheme

Winter 2023

Basics

  1. Write a function to convert fahrenheit to celsius. The formula is c = 5/9(f - 32)
  2. Write a function to compute the distance between two points on the coordinate plane. Have your function take four parameters x1, y1, x2, and y2. Try this one twice:
    1. The first time use a let statement to avoid explicitly subtracting values twice.
    2. The second time, write and use a helper function to compute x2.

Conditionals

  1. Write a function to calculate a salesman's commission. The commission is (For example, the commission on $15,000 in sales would be $1750.)
  2. Write a function that determines the quadrant in which a point lies. Have your function take two parameters: x and y. Write two versions of this function:
    1. Use the cond construct together with and.
    2. Use a nested if (Have the outer if check the x-coordinate, then have the inner, nested if check the y-coordinate.)

Recursion

  1. Write a function log2(val) that returns the integer log base 2 of val. (Use the function truncate-quotient to perform integer division.)
  2. Write a function count-up(from to) that prints all the integers from from to to (inclusive).
  3. Write a function rectangle(width, height) that prints a rectangle of asterisks with the given width and height.
  4. Write a function div-mod(divisor dividend) that returns the quotient and remainder from dividing divisor by dividend. For example, (div-mod 17 5) should return (3, 2) because 17 / 5 = 3 and 17 % 5 = 2. Hint: You might want a helper function.

Lists

  1. Write a function that returns the length of a list
  2. Write a function that counts the number of occurrences of item in the list.
  3. Write a function that inserts item into the list at position x.
  4. Write a function that inserts item into the list after the first occurrence of loc-val.
  5. Write a function that reverses a list.
  6. Implement your own version of append.

Lambdas

  1. Use the map function to convert a list of (firstName, lastName) pairs instructor a list of strings formatted "lastName, firstName". (One option is to use format to build the string.)
  2. Implement your own version of map.
  3. Write a function select that returns the list of items that meet the given criteria. Specifically, select should take a lambda as a parameter. The output list should include all items for which the lambda returns true.
  4. Use your select function to return all the positive numbers in a list.
  5. Use your select function to write a new function high-enough threshold lst that returns all numbers in lst that are greater than or equal to threshold. (To be clear: high-enough should call threshold.)
  6. Implement forEach from to action that runs (action index) for each value of index between from and to (inclusive).
  7. Use map to take a list as input and constrain the values on the list to be between 0 and 100. ( If value is < 0, then set it to 0; If value is > 100, set it to 100)

Fold

  1. Implement max using fold.
  2. Use fold to compute the length of a list.

Updated Monday, 3 April 2023, 9:46 AM

W3c Validation