Homework 6
Last updated: Fri, 10 Nov 2023 16:22:37 -0500
Out: Mon Nov 06, 2023, 00:00 EST
Due: Sun Nov 12, 2023, 23:59 EST
Overview
In this assignment, we’ll practice using accumulators by extending the Editor program from Homework 3 with mouse support.
This hw will be graded as follows:
correctness (8 pts)
design recipe (24 pts)
style (9 pts)
README (1 pts)
Setup
Create a new repository for this assignment by going to the CS450 Fall 2023 GitHub Organization page and clicking "New".
Name the repository <YOUR ACCOUNT NAME>-hw6 where <YOUR ACCOUNT NAME> is your GitHub account name.
For example, if my GitHub account is cs450student then I would name my hw6 repository cs450student-hw6.
Mark the repository as Private.
Check "Add a README file".
Add a .gitignore file for "Racket" to automatically ignore temporarily files.
When done click "Create repository".
Here is (possibly) a hw6 starter repo. You won’t be able to fork it, but, you can copy any files into your own repo and then edit them.
Submitting
1 Before Submitting
Do not submit until all code has been thoroughly tested, independent of the autograder (if there is one), and you are reasonably sure the assignment is complete and correct.
The autograder is not a software development tool so it should not be used as one.
If you submit and get an autograder error, this means the code you wrote is not complete and correct and it’s up to you to figure out why.
The course staff is here and eager to help, of course, but cannot do so without details about what has already been tried. (For example, "why is the autograder giving an error?" is not something we can help with.)
The grading criteria (i.e., test suite) is subject to change. This means that the grade on the preliminary autograder test suite (if one is provided) is not the final grade.
2 Common Problems
Common submission problems:
a required identifier is not provided or defined in the homework file
an external file has not been uploaded to GitHub
the code is in an infinite loop, e.g., do not start a big-bang loop automatically when running a file. (Instead, it should be in a main function)
3 Files
A submission must have the following files in the repository root:
hw6.rkt: Contains the hw solution code.
All defines should use the name specified in the exercise or homework description (ask if you are unsure) and should be provided.
The easiest way to ensure all necessary definitions are provided is to put as the second line in the file:
This automatically provides all definitions in the file. (The first line should be #lang racket)
All code should also follow proper Racket Style.
tests.rkt: This file should require hw6.rkt and define tests for it.
Specifically, it should define a rackunit test-suite which contains sufficient rackunit test cases (e.g., check-equal?, etc.) for each defined function.
README.md: Contains the required README information, including the GitHub repo url.
Also, the repository must have appropriate commit messages. See How to Write a Git Commit Message if you are unsure how to write a commit message.
4 GradeScope
When ready, submit this assignment to GradeScope using the "GitHub" submission feature with your hw6 repository selected.
Submission link: GradeScope HW6
HW Tasks
For this assignment you will extend the Editor from Homework 3. (Hopefully, you followed the The Design Recipe and wrote clean, readable code, so that now it will be easy to remember what it does and reuse it if you need to.)
For this assignment, the program should define a Data Definition called Editor that uses two lists. The rest of the Data Definition details is up to you to decide.
You should also define (and provide) a function called create-editor that takes two string arguments, representing the contents before and after the cursor, respectively, and produces an Editor instance.
The keyboard controls should work as before. Specifically, the editor should handle "left", "right", "\b" (backspace), and the textual "one character" keys, using functions called editor-lft, editor-rgt, editor-del, and editor-ins.
The new part of this assignment is to extend the Editor to respond to a mouse click.
More specifically, if the cursor is within the Editor window, a "click" event should place the cursor in between the closest characters.
While this is not a difficult task, you do need to be a little careful because, if a click is in the middle of a rendered character, you need to decide whether to put the cursor before or after that character, based on whether the cursor position is closer to the left or right side of the character.
To help, you should write a function split that takes an Editor argument and a mouse cursor x position, and computes a new Editor that is properly split. This function should define an internal helper function with a properly specified accumulator invariant.
Keep in mind:
As usual, just "trying to get the code working" will not earn a good grade on this assignment.
Also, all code must follow The Design Recipe. This means that data definitions should be created or updated to properly represent the needed data representations in the program. Further, all functions must have all the required Function Design Recipe components. In particular, you must be able to explain how you arrived at any piece of the code in the program. There should also be a test suite in a file named tests.rkt.
Functions should also be split properly so that each performs "one clear task". One way to know when this is the case is if the function is easy to name and explain concisely. Another way is if a function only processes one kind of data.
Here is an approximation of a correct running program (it’s up and running!).