Difference between revisions of "Spreadsheet Assignment"
Line 115: | Line 115: | ||
which when run will bind <code>split_path</code> to <code>["git","425","sml","spreadsheet"]</code> | which when run will bind <code>split_path</code> to <code>["git","425","sml","spreadsheet"]</code> | ||
==Spreadsheet== | ==Spreadsheet== | ||
+ | |||
+ | === datatype cell === | ||
+ | |||
+ | datatype cell = EMPTY | TEXT of string | INTEGER of int | ||
+ | |||
+ | === type sheet === | ||
+ | |||
+ | type sheet = cell list list | ||
+ | |||
+ | === sheet creation and access functions === | ||
+ | |||
For clarity, we will provide what select functions evaluate to for this spreadsheet: | For clarity, we will provide what select functions evaluate to for this spreadsheet: | ||
{{HockeySpreadsheet}} | {{HockeySpreadsheet}} | ||
− | ===create_sheet=== | + | ====create_sheet==== |
fun create_sheet(word_lists : string list list) : sheet = | fun create_sheet(word_lists : string list list) : sheet = | ||
raise NotYetImplemented | raise NotYetImplemented | ||
− | ===row_count=== | + | ====row_count==== |
fun row_count(s : sheet) : int = | fun row_count(s : sheet) : int = | ||
raise NotYetImplemented | raise NotYetImplemented | ||
− | ====row_count(hockey_spreadsheet) example==== | + | =====row_count(hockey_spreadsheet) example===== |
<code>row_count(hockey_spreadsheet)</code> evaluates to '''4''' | <code>row_count(hockey_spreadsheet)</code> evaluates to '''4''' | ||
{{HockeySpreadsheet}} | {{HockeySpreadsheet}} | ||
− | ===column_count=== | + | ====column_count==== |
fun column_count(s : sheet) : int = | fun column_count(s : sheet) : int = | ||
raise NotYetImplemented | raise NotYetImplemented | ||
− | ====column_count(hockey_spreadsheet)example==== | + | =====column_count(hockey_spreadsheet)example===== |
<code>column_count(hockey_spreadsheet)</code> evaluates to '''6''' | <code>column_count(hockey_spreadsheet)</code> evaluates to '''6''' | ||
{{HockeySpreadsheet}} | {{HockeySpreadsheet}} | ||
− | ===row_at=== | + | ====row_at==== |
fun row_at(s : sheet, row_index : int) : cell list = | fun row_at(s : sheet, row_index : int) : cell list = | ||
raise NotYetImplemented | raise NotYetImplemented | ||
− | ====row_at(hockey_spreadsheet, 0) example==== | + | =====row_at(hockey_spreadsheet, 0) example===== |
<code>row_at(hockey_spreadsheet, 0)</code> evaluates to '''[TEXT("Name"), TEXT("Uniform Number"), TEXT("Birth Year"), TEXT("Games Played"), TEXT("Goals"), TEXT("Assists")]''' | <code>row_at(hockey_spreadsheet, 0)</code> evaluates to '''[TEXT("Name"), TEXT("Uniform Number"), TEXT("Birth Year"), TEXT("Games Played"), TEXT("Goals"), TEXT("Assists")]''' | ||
Line 175: | Line 186: | ||
|} | |} | ||
− | ====row_at(hockey_spreadsheet, 1) example==== | + | =====row_at(hockey_spreadsheet, 1) example===== |
<code>row_at(hockey_spreadsheet, 1)</code> evaluates to '''[TEXT("Bobby Orr"), VALUE(4), VALUE(1948), VALUE(657), VALUE(270), VALUE(645)]''' | <code>row_at(hockey_spreadsheet, 1)</code> evaluates to '''[TEXT("Bobby Orr"), VALUE(4), VALUE(1948), VALUE(657), VALUE(270), VALUE(645)]''' | ||
Line 209: | Line 220: | ||
|} | |} | ||
− | ====row_at(hockey_spreadsheet, 2) example==== | + | =====row_at(hockey_spreadsheet, 2) example===== |
<code>row_at(hockey_spreadsheet, 2)</code> evaluates to '''[TEXT("Wayne Gretzky"), VALUE(99), VALUE(1961), VALUE(1487), VALUE(894), VALUE(1963)]''' | <code>row_at(hockey_spreadsheet, 2)</code> evaluates to '''[TEXT("Wayne Gretzky"), VALUE(99), VALUE(1961), VALUE(1487), VALUE(894), VALUE(1963)]''' | ||
Line 243: | Line 254: | ||
|} | |} | ||
− | ====row_at(hockey_spreadsheet, 3) example==== | + | =====row_at(hockey_spreadsheet, 3) example===== |
<code>row_at(hockey_spreadsheet, 3)</code> evaluates to '''[TEXT("Mario Lemieux"), VALUE(66), VALUE(1965), VALUE(915), VALUE(690), VALUE(1033)]''' | <code>row_at(hockey_spreadsheet, 3)</code> evaluates to '''[TEXT("Mario Lemieux"), VALUE(66), VALUE(1965), VALUE(915), VALUE(690), VALUE(1033)]''' | ||
Line 277: | Line 288: | ||
|} | |} | ||
− | ===cell_in_row_at_column_index=== | + | ====cell_in_row_at_column_index==== |
fun cell_in_row_at_column_index( r : cell list, col_index : int) : cell = | fun cell_in_row_at_column_index( r : cell list, col_index : int) : cell = | ||
raise NotYetImplemented | raise NotYetImplemented | ||
− | ===cell_at (Provided)=== | + | ====cell_at (Provided)==== |
fun cell_at(s : sheet, row_index : int, col_index : int) : cell = | fun cell_at(s : sheet, row_index : int, col_index : int) : cell = | ||
cell_in_row_at_column_index(row_at(s, row_index), col_index) | cell_in_row_at_column_index(row_at(s, row_index), col_index) | ||
Line 287: | Line 298: | ||
'''cell_at'''(hockey_spreadsheet, 1, 2) evaluates to '''1948''' | '''cell_at'''(hockey_spreadsheet, 1, 2) evaluates to '''1948''' | ||
− | ===column_at=== | + | ====column_at==== |
fun column_at(s : sheet, col_index : int) : cell list = | fun column_at(s : sheet, col_index : int) : cell list = | ||
raise NotYetImplemented | raise NotYetImplemented | ||
Line 293: | Line 304: | ||
'''column_at'''(hockey_spreadsheet, 3) evaluates to '''[TEXT("Games Played"), VALUE(657), VALUE(1487), VALUE(915)]''' | '''column_at'''(hockey_spreadsheet, 3) evaluates to '''[TEXT("Games Played"), VALUE(657), VALUE(1487), VALUE(915)]''' | ||
− | ====column_at(hockey_spreadsheet, 3) example==== | + | =====column_at(hockey_spreadsheet, 3) example===== |
<code>column_at(hockey_spreadsheet, 3)</code> evaluates to '''[TEXT("Games Played"), VALUE(657), VALUE(1487), VALUE(915)]''' | <code>column_at(hockey_spreadsheet, 3)</code> evaluates to '''[TEXT("Games Played"), VALUE(657), VALUE(1487), VALUE(915)]''' | ||
Line 326: | Line 337: | ||
|} | |} | ||
− | ===sum_values_in_cell_list=== | + | === equation: sum === |
+ | |||
+ | ====sum_values_in_cell_list==== | ||
fun sum_values_in_cell_list(cells : cell list) : int = | fun sum_values_in_cell_list(cells : cell list) : int = | ||
raise NotYetImplemented | raise NotYetImplemented | ||
− | ===sum_values_in_row (Provided)=== | + | ====sum_values_in_row (Provided)==== |
fun sum_values_in_row(s : sheet, row_index : int) : int = | fun sum_values_in_row(s : sheet, row_index : int) : int = | ||
sum_values_in_cell_list(row_at(s, row_index)) | sum_values_in_cell_list(row_at(s, row_index)) | ||
− | ===sum_values_in_column (Provided)=== | + | ====sum_values_in_column (Provided)==== |
fun sum_values_in_column(s : sheet, column_index : int) : int = | fun sum_values_in_column(s : sheet, column_index : int) : int = | ||
sum_values_in_cell_list(column_at(s, column_index)) | sum_values_in_cell_list(column_at(s, column_index)) | ||
− | ===max_value_in_cell_list=== | + | === equation: max === |
+ | |||
+ | ====max_value_in_cell_list==== | ||
fun max_value_in_cell_list(cells : cell list) : int option = | fun max_value_in_cell_list(cells : cell list) : int option = | ||
raise NotYetImplemented | raise NotYetImplemented | ||
− | ===max_value_in_row (Provided)=== | + | ====max_value_in_row (Provided)==== |
fun max_value_in_row(s : sheet, row_index : int) : int option = | fun max_value_in_row(s : sheet, row_index : int) : int option = | ||
max_value_in_cell_list(row_at(s, row_index)) | max_value_in_cell_list(row_at(s, row_index)) | ||
− | ===max_value_in_column (Provided)=== | + | ====max_value_in_column (Provided)==== |
fun max_value_in_column(s : sheet, column_index : int) : int option = | fun max_value_in_column(s : sheet, column_index : int) : int option = | ||
max_value_in_cell_list(column_at(s, column_index)) | max_value_in_cell_list(column_at(s, column_index)) | ||
+ | |||
+ | === equation: count if === | ||
===count_if_in_cell_list=== | ===count_if_in_cell_list=== |
Revision as of 01:49, 26 September 2022
Contents
- 1 Slides
- 2 Spreadsheet Examples
- 3 Basis Library
- 4 Code To Implement
- 4.1 Csv
- 4.2 Spreadsheet
- 4.2.1 datatype cell
- 4.2.2 type sheet
- 4.2.3 sheet creation and access functions
- 4.2.4 equation: sum
- 4.2.5 equation: max
- 4.2.6 equation: count if
- 4.2.7 count_if_in_cell_list
- 4.2.8 count_if_in_row (Provided)
- 4.2.9 count_if_in_column (Provided)
- 5 Testing
- 6 Pledge, Acknowledgments, Citations
Slides
Spreadsheet Examples
nums
This rather simple spreadsheet is comprised entirely of ints.
1 | 2 | 3 | 4 |
10 | 20 | 30 | 40 |
grades
In this spreadsheet we can see that Joshua Bloch is rocking out the Java assignments in 425, Dan Grossman is allowing his subconscious disdain for Java to affect his ability with those assignments, and Shannon O'Ganns was failing poorly enough to seemingly resort to some sort of subversion of the grading process.
Name | Java List | SML Calendar | SML Hearts | SML Card Game | Java HOF | SML Binary Tree | SML Pattern Matching |
Max | 100 | 104 | 100 | 104 | 100 | 100 | 105 |
Joshua Bloch | 100 | 85 | 80 | 75 | 100 | 70 | 65 |
Harry Q. Bovik | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
Dan Grossman | 75 | 104 | 100 | 104 | 80 | 100 | 105 |
Shannon O'Ganns | 70 | 40 | 0 | 120 | 120 | 130 | 140 |
hockey
In this spreadsheet we have the three greatest hockey players of all time with some of their stats. Although not particularly interesting from a computer science perspective, it is remarkable that Wayne Gretzky has more assists than the year of his birth.
Name | Uniform Number | Birth Year | Games Played | Goals | Assists |
Bobby Orr | 4 | 1948 | 657 | 270 | 645 |
Wayne Gretzky | 99 | 1961 | 1487 | 894 | 1963 |
Mario Lemieux | 66 | 1965 | 915 | 690 | 1033 |
Basis Library
Option
String
Int
List
Code To Implement
NOTE: For both CSV and Spreadsheet functions, you may assume that all rows will have the same number of columns.
Csv
read_csv
fun read_csv(csv:string) : string list list = raise NotYetImplemented
It is highly recommended that you use the String fields function. NOTE: fields is curried. You have been provided with an example usage of fields in string_fields_example.sml:
fun is_separator(c : char) : bool = c = #"/" val split_path = String.fields is_separator "git/425/sml/spreadsheet"
which when run will bind split_path
to ["git","425","sml","spreadsheet"]
Spreadsheet
datatype cell
datatype cell = EMPTY | TEXT of string | INTEGER of int
type sheet
type sheet = cell list list
sheet creation and access functions
For clarity, we will provide what select functions evaluate to for this spreadsheet:
Name | Uniform Number | Birth Year | Games Played | Goals | Assists |
Bobby Orr | 4 | 1948 | 657 | 270 | 645 |
Wayne Gretzky | 99 | 1961 | 1487 | 894 | 1963 |
Mario Lemieux | 66 | 1965 | 915 | 690 | 1033 |
create_sheet
fun create_sheet(word_lists : string list list) : sheet = raise NotYetImplemented
row_count
fun row_count(s : sheet) : int = raise NotYetImplemented
row_count(hockey_spreadsheet) example
row_count(hockey_spreadsheet)
evaluates to 4
Name | Uniform Number | Birth Year | Games Played | Goals | Assists |
Bobby Orr | 4 | 1948 | 657 | 270 | 645 |
Wayne Gretzky | 99 | 1961 | 1487 | 894 | 1963 |
Mario Lemieux | 66 | 1965 | 915 | 690 | 1033 |
column_count
fun column_count(s : sheet) : int = raise NotYetImplemented
column_count(hockey_spreadsheet)example
column_count(hockey_spreadsheet)
evaluates to 6
Name | Uniform Number | Birth Year | Games Played | Goals | Assists |
Bobby Orr | 4 | 1948 | 657 | 270 | 645 |
Wayne Gretzky | 99 | 1961 | 1487 | 894 | 1963 |
Mario Lemieux | 66 | 1965 | 915 | 690 | 1033 |
row_at
fun row_at(s : sheet, row_index : int) : cell list = raise NotYetImplemented
row_at(hockey_spreadsheet, 0) example
row_at(hockey_spreadsheet, 0)
evaluates to [TEXT("Name"), TEXT("Uniform Number"), TEXT("Birth Year"), TEXT("Games Played"), TEXT("Goals"), TEXT("Assists")]
Name | Uniform Number | Birth Year | Games Played | Goals | Assists |
Bobby Orr | 4 | 1948 | 657 | 270 | 645 |
Wayne Gretzky | 99 | 1961 | 1487 | 894 | 1963 |
Mario Lemieux | 66 | 1965 | 915 | 690 | 1033 |
row_at(hockey_spreadsheet, 1) example
row_at(hockey_spreadsheet, 1)
evaluates to [TEXT("Bobby Orr"), VALUE(4), VALUE(1948), VALUE(657), VALUE(270), VALUE(645)]
Name | Uniform Number | Birth Year | Games Played | Goals | Assists |
Bobby Orr | 4 | 1948 | 657 | 270 | 645 |
Wayne Gretzky | 99 | 1961 | 1487 | 894 | 1963 |
Mario Lemieux | 66 | 1965 | 915 | 690 | 1033 |
row_at(hockey_spreadsheet, 2) example
row_at(hockey_spreadsheet, 2)
evaluates to [TEXT("Wayne Gretzky"), VALUE(99), VALUE(1961), VALUE(1487), VALUE(894), VALUE(1963)]
Name | Uniform Number | Birth Year | Games Played | Goals | Assists |
Bobby Orr | 4 | 1948 | 657 | 270 | 645 |
Wayne Gretzky | 99 | 1961 | 1487 | 894 | 1963 |
Mario Lemieux | 66 | 1965 | 915 | 690 | 1033 |
row_at(hockey_spreadsheet, 3) example
row_at(hockey_spreadsheet, 3)
evaluates to [TEXT("Mario Lemieux"), VALUE(66), VALUE(1965), VALUE(915), VALUE(690), VALUE(1033)]
Name | Uniform Number | Birth Year | Games Played | Goals | Assists |
Bobby Orr | 4 | 1948 | 657 | 270 | 645 |
Wayne Gretzky | 99 | 1961 | 1487 | 894 | 1963 |
Mario Lemieux | 66 | 1965 | 915 | 690 | 1033 |
cell_in_row_at_column_index
fun cell_in_row_at_column_index( r : cell list, col_index : int) : cell = raise NotYetImplemented
cell_at (Provided)
fun cell_at(s : sheet, row_index : int, col_index : int) : cell = cell_in_row_at_column_index(row_at(s, row_index), col_index)
cell_at(hockey_spreadsheet, 1, 2) evaluates to 1948
column_at
fun column_at(s : sheet, col_index : int) : cell list = raise NotYetImplemented
column_at(hockey_spreadsheet, 3) evaluates to [TEXT("Games Played"), VALUE(657), VALUE(1487), VALUE(915)]
column_at(hockey_spreadsheet, 3) example
column_at(hockey_spreadsheet, 3)
evaluates to [TEXT("Games Played"), VALUE(657), VALUE(1487), VALUE(915)]
Name | Uniform Number | Birth Year | Games Played | Goals | Assists |
Bobby Orr | 4 | 1948 | 657 | 270 | 645 |
Wayne Gretzky | 99 | 1961 | 1487 | 894 | 1963 |
Mario Lemieux | 66 | 1965 | 915 | 690 | 1033 |
equation: sum
sum_values_in_cell_list
fun sum_values_in_cell_list(cells : cell list) : int = raise NotYetImplemented
sum_values_in_row (Provided)
fun sum_values_in_row(s : sheet, row_index : int) : int = sum_values_in_cell_list(row_at(s, row_index))
sum_values_in_column (Provided)
fun sum_values_in_column(s : sheet, column_index : int) : int = sum_values_in_cell_list(column_at(s, column_index))
equation: max
max_value_in_cell_list
fun max_value_in_cell_list(cells : cell list) : int option = raise NotYetImplemented
max_value_in_row (Provided)
fun max_value_in_row(s : sheet, row_index : int) : int option = max_value_in_cell_list(row_at(s, row_index))
max_value_in_column (Provided)
fun max_value_in_column(s : sheet, column_index : int) : int option = max_value_in_cell_list(column_at(s, column_index))
equation: count if
count_if_in_cell_list
fun count_if_in_cell_list(cells : cell list, predicate : (cell -> bool)) : int = raise NotYetImplemented
count_if_in_row (Provided)
fun count_if_in_row(s : sheet, row_index : int, predicate : (cell -> bool)) : int = count_if_in_cell_list(row_at(s, row_index), predicate)
count_if_in_column (Provided)
fun count_if_in_column(s : sheet, col_index : int, predicate : (cell -> bool)) : int = count_if_in_cell_list(column_at(s, col_index), predicate)
Testing
source folder: | src/test/sml/spreadsheet |
how to run with CM.make verbosity off: | sml -Ccm.verbose=false run_spreadsheet_testing.sml |
how to run with CM.make verbosity on: | sml run_spreadsheet_testing.sml |
note: ensure that you have removed all printing to receive credit for any assignment.
Pledge, Acknowledgments, Citations
file: | studio-spreadsheet-pledge-acknowledgments-citations.txt |
More info about the Honor Pledge