Difference between revisions of "Spreadsheet Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
 
(33 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Slides=
 
[https://docs.google.com/presentation/d/1AFIbOD_9Bjl-TP9q42AvV-BRHaF856b4Y1Kc54jYmUA/view view slides]
 
 
 
=Spreadsheet Examples=
 
=Spreadsheet Examples=
 
==nums==
 
==nums==
Line 79: Line 76:
 
==hockey==
 
==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.
 
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.
 +
 +
{{HockeySpreadsheet}}
 +
 +
=Basis Library=
 +
==[https://smlfamily.github.io/Basis/option.html Option]==
 +
*[https://smlfamily.github.io/Basis/option.html#SIG:OPTION.option:TY NONE]
 +
*[https://smlfamily.github.io/Basis/option.html#SIG:OPTION.option:TY SOME(v)]
 +
==[https://smlfamily.github.io/Basis/string.html String]==
 +
* [https://smlfamily.github.io/Basis/string.html#SIG:STRING.tokens:VAL fields] NOTE: curried
 +
* [https://smlfamily.github.io/Basis/string.html#SIG:STRING.size:VAL size]
 +
==[https://smlfamily.github.io/Basis/integer.html Int]==
 +
* [https://smlfamily.github.io/Basis/integer.html#SIG:INTEGER.fromString:VAL fromString]
 +
* [https://smlfamily.github.io/Basis/integer.html#SIG:INTEGER.max:VAL max]
 +
==[https://smlfamily.github.io/Basis/list.html List]==
 +
* [https://smlfamily.github.io/Basis/list.html#SIG:LIST.length:VAL length]
 +
* [https://smlfamily.github.io/Basis/list.html#SIG:LIST.nth:VAL nth]
 +
* [https://smlfamily.github.io/Basis/list.html#SIG:LIST.map:VAL map] NOTE: curried
 +
* [https://smlfamily.github.io/Basis/list.html#SIG:LIST.foldl:VAL foldl] or [https://smlfamily.github.io/Basis/list.html#SIG:LIST.foldr:VAL foldr] NOTE: both curried
 +
 +
=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===
 +
<syntaxhighlight lang="sml">
 +
fun read_csv(csv:string) : string list list =
 +
    raise Fail "NotYetImplemented"
 +
</syntaxhighlight>
 +
 +
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:
 +
 +
<syntaxhighlight lang="sml">
 +
fun is_separator(c : char) : bool =
 +
    c = #"/"
 +
 +
val split_path = String.fields is_separator "git/425/sml/spreadsheet"</nowiki>
 +
</syntaxhighlight>
 +
 +
which when run will bind <code>split_path</code> to <code>["git","425","sml","spreadsheet"]</code>
 +
 +
==Spreadsheet==
 +
=== types ===
 +
==== datatype cell ====
 +
<syntaxhighlight lang="sml">
 +
datatype cell = EMPTY | TEXT of string | INTEGER of int
 +
</syntaxhighlight>
 +
==== type sheet ====
 +
<syntaxhighlight lang="sml">
 +
type sheet = cell list list
 +
</syntaxhighlight>
 +
=== sheet creation and access functions ===
 +
 +
For clarity, we will provide what select functions evaluate to for this spreadsheet:
 +
{{HockeySpreadsheet}}
 +
====create_sheet====
 +
<syntaxhighlight lang="sml">
 +
fun create_sheet(word_lists : string list list) : sheet =
 +
        raise Fail "NotYetImplemented"
 +
</syntaxhighlight>
 +
====row_count====
 +
<syntaxhighlight lang="sml">
 +
fun row_count(s : sheet) : int =
 +
        raise Fail "NotYetImplemented"
 +
</syntaxhighlight>
 +
 +
=====row_count(hockey_spreadsheet) example=====
 +
<code>row_count(hockey_spreadsheet)</code> evaluates to '''4'''
 +
 +
{{HockeySpreadsheet}}
 +
====column_count====
 +
<syntaxhighlight lang="sml">
 +
fun column_count(s : sheet) : int =
 +
        raise Fail "NotYetImplemented"
 +
</syntaxhighlight>
 +
 +
=====column_count(hockey_spreadsheet)example=====
 +
<code>column_count(hockey_spreadsheet)</code> evaluates to '''6'''
 +
 +
{{HockeySpreadsheet}}
 +
====row_at====
 +
<syntaxhighlight lang="sml">
 +
fun row_at(s : sheet, row_index : int) : cell list =
 +
        raise Fail "NotYetImplemented"
 +
</syntaxhighlight>
 +
 +
=====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")]'''
  
 
{| class="wikitable"
 
{| class="wikitable"
 +
|- style="background-color:#6b9ac4;
 
|Name
 
|Name
 
|Uniform Number
 
|Uniform Number
Line 87: Line 172:
 
|Goals
 
|Goals
 
|Assists
 
|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=====
 +
 +
<code>row_at(hockey_spreadsheet, 1)</code> evaluates to '''[TEXT("Bobby Orr"), INTEGER(4), INTEGER(1948), INTEGER(657), INTEGER(270), INTEGER(645)]'''
 +
 +
{| class="wikitable"
 +
|Name
 +
|Uniform Number
 +
|Birth Year
 +
|Games Played
 +
|Goals
 +
|Assists
 +
|- style="background-color:#6b9ac4;
 
|Bobby Orr
 
|Bobby Orr
 
|4
 
|4
Line 110: Line 229:
 
|}
 
|}
  
=Basis Library=
+
=====row_at(hockey_spreadsheet, 2) example=====
==[https://smlfamily.github.io/Basis/option.html Option]==
+
 
*[https://smlfamily.github.io/Basis/option.html#SIG:OPTION.option:TY NONE]
+
<code>row_at(hockey_spreadsheet, 2)</code> evaluates to '''[TEXT("Wayne Gretzky"), INTEGER(99), INTEGER(1961), INTEGER(1487), INTEGER(894), INTEGER(1963)]'''
*[https://smlfamily.github.io/Basis/option.html#SIG:OPTION.option:TY SOME(v)]
+
 
==[https://smlfamily.github.io/Basis/string.html String]==
+
{| class="wikitable"
* [https://smlfamily.github.io/Basis/string.html#SIG:STRING.tokens:VAL fields] NOTE: curried
+
|Name
* [https://smlfamily.github.io/Basis/string.html#SIG:STRING.size:VAL size]
+
|Uniform Number
==[https://smlfamily.github.io/Basis/integer.html Int]==
+
|Birth Year
* [https://smlfamily.github.io/Basis/integer.html#SIG:INTEGER.fromString:VAL fromString]
+
|Games Played
* [https://smlfamily.github.io/Basis/integer.html#SIG:INTEGER.max:VAL max]
+
|Goals
==[https://smlfamily.github.io/Basis/list.html List]==
+
|Assists
* [https://smlfamily.github.io/Basis/list.html#SIG:LIST.length:VAL length]
+
|-
* [https://smlfamily.github.io/Basis/list.html#SIG:LIST.nth:VAL nth]
+
|Bobby Orr
* [https://smlfamily.github.io/Basis/list.html#SIG:LIST.map:VAL map] NOTE: curried
+
|4
* [https://smlfamily.github.io/Basis/list.html#SIG:LIST.foldl:VAL foldl] or [https://smlfamily.github.io/Basis/list.html#SIG:LIST.foldr:VAL foldr] NOTE: both curried
+
|1948
 +
|657
 +
|270
 +
|645
 +
|- style="background-color:#6b9ac4;
 +
|Wayne Gretzky
 +
|99
 +
|1961
 +
|1487
 +
|894
 +
|1963
 +
|-
 +
|Mario Lemieux
 +
|66
 +
|1965
 +
|915
 +
|690
 +
|1033
 +
|}
 +
 
 +
=====row_at(hockey_spreadsheet, 3) example=====
 +
 
 +
<code>row_at(hockey_spreadsheet, 3)</code> evaluates to '''[TEXT("Mario Lemieux"), INTEGER(66), INTEGER(1965), INTEGER(915), INTEGER(690), INTEGER(1033)]'''
 +
 
 +
{| class="wikitable"
 +
|Name
 +
|Uniform Number
 +
|Birth Year
 +
|Games Played
 +
|Goals
 +
|Assists
 +
|-
 +
|Bobby Orr
 +
|4
 +
|1948
 +
|657
 +
|270
 +
|645
 +
|-
 +
|Wayne Gretzky
 +
|99
 +
|1961
 +
|1487
 +
|894
 +
|1963
 +
|- style="background-color:#6b9ac4;
 +
|Mario Lemieux
 +
|66
 +
|1965
 +
|915
 +
|690
 +
|1033
 +
|}
 +
 
 +
====cell_in_row_at_column_index====
 +
<syntaxhighlight lang="sml">
 +
fun cell_in_row_at_column_index( r : cell list, col_index : int) : cell =
 +
        raise Fail "NotYetImplemented"
 +
</syntaxhighlight>
 +
 
 +
====cell_at (Provided)====
 +
<syntaxhighlight lang="sml">
 +
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)
 +
</syntaxhighlight>
  
=Code To Implement=
+
'''cell_at'''(hockey_spreadsheet, 1, 2) evaluates to '''1948'''
NOTE: For both CSV and Spreadsheet functions, you may assume that all rows will have the same number of columns.
 
  
==Csv==
+
====column_at====
===read_csv===
+
<syntaxhighlight lang="sml">
fun read_csv(csv:string) : string list list =
+
fun column_at(s : sheet, col_index : int) : cell list =
    raise NotYetImplemented
+
        raise Fail "NotYetImplemented"
 +
</syntaxhighlight>
  
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:
+
=====column_at(hockey_spreadsheet, 3) example=====
 +
<code>column_at(hockey_spreadsheet, 3)</code> evaluates to '''[TEXT("Games Played"), INTEGER(657), INTEGER(1487), INTEGER(915)]'''
  
<nowiki>fun is_separator(c : char) : bool =
+
{| class="wikitable"
        c = #"/"
+
|Name
 +
|Uniform Number
 +
|Birth Year
 +
|style="background-color:#6b9ac4;|Games Played
 +
|Goals
 +
|Assists
 +
|-
 +
|Bobby Orr
 +
|4
 +
|1948
 +
|style="background-color:#6b9ac4;|657
 +
|270
 +
|645
 +
|-
 +
|Wayne Gretzky
 +
|99
 +
|1961
 +
|style="background-color:#6b9ac4;|1487
 +
|894
 +
|1963
 +
|-
 +
|Mario Lemieux
 +
|66
 +
|1965
 +
|style="background-color:#6b9ac4;|915
 +
|690
 +
|1033
 +
|}
  
val split_path = String.fields is_separator "git/425/sml/spreadsheet"</nowiki>
+
=== equation: sum ===
 +
Functions <code>sum_in_row</code> and <code>sum_in_column</code> are provided.  Each invokes <code>sum_in_cell_list</code> which you will implement.
  
which when run will bind <code>split_path</code> to <code>["git","425","sml","spreadsheet"]</code>
+
====sum_in_cell_list====
 +
<syntaxhighlight lang="sml">
 +
fun sum_in_cell_list(cells : cell list) : int =
 +
        raise Fail "NotYetImplemented"
 +
</syntaxhighlight>
  
==Spreadsheet==
+
Sum the INTEGER cell values.
  
For clarity, we will provide what select functions evaluate to for this spreadsheet:
+
====sum_in_row (Provided)====
 +
<syntaxhighlight lang="sml">
 +
fun sum_in_row(s : sheet, row_index : int) : int =
 +
        sum_in_cell_list(row_at(s, row_index))
 +
</syntaxhighlight>
  
 +
=====sum_in_row 0 example=====
 +
<code>sum_in_row(hockey_spreadsheet, 0)</code> evaluates to '''0'''
 
{| class="wikitable"
 
{| class="wikitable"
 +
|- style="background-color:#6b9ac4;
 
|Name
 
|Name
 
|Uniform Number
 
|Uniform Number
Line 154: Line 377:
 
|Goals
 
|Goals
 
|Assists
 
|Assists
 +
|-
 +
|Bobby Orr
 +
|4
 +
|1948
 +
|657
 +
|270
 +
|645
 
|-
 
|-
 +
|Wayne Gretzky
 +
|99
 +
|1961
 +
|1487
 +
|894
 +
|1963
 +
|-
 +
|Mario Lemieux
 +
|66
 +
|1965
 +
|915
 +
|690
 +
|1033
 +
|}
 +
=====sum_in_row 1 example=====
 +
<code>sum_in_row(hockey_spreadsheet, 1)</code> evaluates to '''3524'''
 +
 +
{| class="wikitable"
 +
|Name
 +
|Uniform Number
 +
|Birth Year
 +
|Games Played
 +
|Goals
 +
|Assists
 +
|- style="background-color:#6b9ac4;
 
|Bobby Orr
 
|Bobby Orr
 
|4
 
|4
Line 177: Line 432:
 
|}
 
|}
  
===create_sheet===
+
====sum_in_column (Provided)====
fun create_sheet(word_lists : string list list) : sheet =
+
<syntaxhighlight lang="sml">
         raise NotYetImplemented
+
fun sum_in_column(s : sheet, column_index : int) : int =
 +
         sum_in_cell_list(column_at(s, column_index))
 +
</syntaxhighlight>
  
===row_count===
+
=====sum_in_column 3 example=====
fun row_count(s : sheet) : int =
+
<code>sum_in_column(hockey_spreadsheet, 3)</code> evaluates to '''3059'''
        raise NotYetImplemented
 
  
'''row_count'''(hockey_spreadsheet) evaluates to '''4'''
+
{| class="wikitable"
===column_count===
+
|Name
fun column_count(s : sheet) : int =
+
|Uniform Number
        raise NotYetImplemented
+
|Birth Year
 +
|style="background-color:#6b9ac4;|Games Played
 +
|Goals
 +
|Assists
 +
|-
 +
|Bobby Orr
 +
|4
 +
|1948
 +
|style="background-color:#6b9ac4;|657
 +
|270
 +
|645
 +
|-
 +
|Wayne Gretzky
 +
|99
 +
|1961
 +
|style="background-color:#6b9ac4;|1487
 +
|894
 +
|1963
 +
|-
 +
|Mario Lemieux
 +
|66
 +
|1965
 +
|style="background-color:#6b9ac4;|915
 +
|690
 +
|1033
 +
|}
  
'''column_count'''(hockey_spreadsheet) evaluates to '''6'''
+
=== equation: max ===
 +
Functions <code>max_in_row</code> and <code>max_in_column</code> are provided.  Each invokes <code>max_value_in_cell_list</code> which you will implement.
 +
====max_value_in_cell_list====
 +
<syntaxhighlight lang="sml">
 +
fun max_in_cell_list(cells : cell list) : int option =
 +
        raise Fail "NotYetImplemented"
 +
</syntaxhighlight>
  
===row_at===
+
Evaluate to SOME of the maximum the INTEGER cell, if found. Otherwise evaluate to NONE.
  fun row_at(s : sheet, row_index : int) : cell list =
 
        raise NotYetImplemented
 
  
===cell_in_row_at_column_index===
+
====max_in_row (Provided)====
fun cell_in_row_at_column_index( r : cell list, col_index : int) : cell =  
+
<syntaxhighlight lang="sml">
         raise NotYetImplemented
+
fun max_value_in_row(s : sheet, row_index : int) : int option =
 +
         max_value_in_cell_list(row_at(s, row_index))
 +
</syntaxhighlight>
  
===cell_at (Provided)===
+
=====max_in_row 0 example=====
fun cell_at(s : sheet, row_index : int, col_index : int) : cell =  
+
<code>max_in_row(hockey_spreadsheet, 0)</code> evaluates to '''NONE'''
        cell_in_row_at_column_index(row_at(s, row_index), col_index)
+
{| class="wikitable"
 +
|- style="background-color:#6b9ac4;
 +
|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
 +
|}
 +
=====max_in_row 1 example=====
 +
<code>max_in_row(hockey_spreadsheet, 1)</code> evaluates to '''SOME(1948)'''
  
'''cell_at'''(hockey_spreadsheet, 1, 2) evaluates to '''1948'''
+
{| class="wikitable"
 +
|Name
 +
|Uniform Number
 +
|Birth Year
 +
|Games Played
 +
|Goals
 +
|Assists
 +
|- style="background-color:#6b9ac4;
 +
|Bobby Orr
 +
|4
 +
|1948
 +
|657
 +
|270
 +
|645
 +
|-
 +
|Wayne Gretzky4
 +
|99
 +
|1961
 +
|1487
 +
|894
 +
|1963
 +
|-
 +
|Mario Lemieux
 +
|66
 +
|1965
 +
|915
 +
|690
 +
|1033
 +
|}
  
===column_at===
+
====max_in_column (Provided)====
fun column_at(s : sheet, col_index : int) : cell list =
+
<syntaxhighlight lang="sml">
         raise NotYetImplemented
+
fun max_in_column(s : sheet, column_index : int) : int option =
 +
         max_in_cell_list(column_at(s, column_index))
 +
</syntaxhighlight>
  
'''column_at'''(hockey_spreadsheet, 3) evaluates to '''[TEXT("Games Played"), VALUE(657), VALUE(1487), VALUE(915)]'''
+
=====max_in_column 3 example=====
 +
<code>max_in_column(hockey_spreadsheet, 3)</code> evaluates to '''SOME(1487)'''
  
===sum_values_in_cell_list===
+
{| class="wikitable"
fun sum_values_in_cell_list(cells : cell list) : int =
+
|Name
        raise NotYetImplemented
+
|Uniform Number
 +
|Birth Year
 +
|style="background-color:#6b9ac4;|Games Played
 +
|Goals
 +
|Assists
 +
|-
 +
|Bobby Orr
 +
|4
 +
|1948
 +
|style="background-color:#6b9ac4;|657
 +
|270
 +
|645
 +
|-
 +
|Wayne Gretzky
 +
|99
 +
|1961
 +
|style="background-color:#6b9ac4;|1487
 +
|894
 +
|1963
 +
|-
 +
|Mario Lemieux
 +
|66
 +
|1965
 +
|style="background-color:#6b9ac4;|915
 +
|690
 +
|1033
 +
|}
  
===sum_values_in_row (Provided)===
+
=== equation: count if ===
  fun sum_values_in_row(s : sheet, row_index : int) : int =
+
Functions <code>max_in_row</code> and <code>max_in_column</code> are provided. Each invokes <code>max_value_in_cell_list</code> which you will implement.
        sum_values_in_cell_list(row_at(s, row_index))
 
  
===sum_values_in_column (Provided)===
+
For the examples we will use this simple function:
fun sum_values_in_column(s : sheet, column_index : int) : int =
 
        sum_values_in_cell_list(column_at(s, column_index))
 
  
===max_value_in_cell_list===
+
<syntaxhighlight lang="sml">
fun max_value_in_cell_list(cells : cell list) : int option =
+
fun is_even(cell) =  
        raise NotYetImplemented
+
    case cell of
 +
          EMPTY => false
 +
    |    TEXT(_) => false
 +
    | INTEGER(v) => (v mod 2) = 0
 +
</syntaxhighlight>
  
===max_value_in_row (Provided)===
+
====count_if_in_cell_list====
  fun max_value_in_row(s : sheet, row_index : int) : int option =
+
<syntaxhighlight lang="sml">
         max_value_in_cell_list(row_at(s, row_index))
+
  fun count_if_in_cell_list(cells : cell list, predicate : (cell -> bool)) : int =  
 +
         raise Fail "NotYetImplemented"
 +
</syntaxhighlight>
  
===max_value_in_column (Provided)===
+
Count the number of cells that pass the specified predicate test function.
fun max_value_in_column(s : sheet, column_index : int) : int option =
 
        max_value_in_cell_list(column_at(s, column_index))
 
 
 
===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)===
+
====count_if_in_row (Provided)====
fun count_if_in_row(s : sheet, row_index : int, predicate : (cell -> bool)) : int =  
+
<syntaxhighlight lang="sml">
 +
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_cell_list(row_at(s, row_index), predicate)
 +
</syntaxhighlight>
  
===count_if_in_column (Provided)===
+
=====count_if_in_row 0 example=====
fun count_if_in_column(s : sheet, col_index : int, predicate : (cell -> bool)) : int =
+
<code>count_if_in_row(hockey_spreadsheet, 0, is_even)</code> evaluates to '''0'''
        count_if_in_cell_list(column_at(s, col_index), predicate)
+
{| class="wikitable"
 
+
|- style="background-color:#6b9ac4;
===to_dictionaries_using_headers_as_keys===
+
|Name
fun to_dictionaries_using_headers_as_keys(s : sheet) : (cell,cell) SingleListDictionary.dictionary list =
+
|Uniform Number
        raise NotYetImplemented
+
|Birth Year
 
+
|Games Played
Given this spreadsheet:
+
|Goals
 +
|Assists
 +
|-
 +
|Bobby Orr
 +
|4
 +
|1948
 +
|657
 +
|270
 +
|645
 +
|-
 +
|Wayne Gretzky
 +
|99
 +
|1961
 +
|1487
 +
|894
 +
|1963
 +
|-
 +
|Mario Lemieux
 +
|66
 +
|1965
 +
|915
 +
|690
 +
|1033
 +
|}
 +
=====count_if_in_row 1 example=====
 +
<code>count_if_in_row(hockey_spreadsheet, 1, is_even)</code> evaluates to '''3'''
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 261: Line 660:
 
|Goals
 
|Goals
 
|Assists
 
|Assists
|-
+
|- style="background-color:#6b9ac4;
 
|Bobby Orr
 
|Bobby Orr
 
|4
 
|4
Line 269: Line 668:
 
|645
 
|645
 
|-
 
|-
|Wayne Gretzky
+
|Wayne Gretzky4
 
|99
 
|99
 
|1961
 
|1961
Line 284: Line 683:
 
|}
 
|}
  
<code>to_dictionaries_using_headers_as_keys</code> should return a list with 3 single list dictionaries, one for each non-header row.  The dictionaries would be filled with entries for each column, using the cell in the header of the column as the key and the cell in the particular row of the column as the value.
+
====count_if_in_column (Provided)====
 +
<syntaxhighlight lang="sml">
 +
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)
 +
</syntaxhighlight>
 +
 
 +
=====count_if_in_column 1 example=====
 +
<code>count_if_in_column(hockey_spreadsheet, 1, is_even)</code> evaluates to '''2'''
 +
 
 +
{| class="wikitable"
 +
|Name
 +
|style="background-color:#6b9ac4;|Uniform Number
 +
|Birth Year
 +
|Games Played
 +
|Goals
 +
|Assists
 +
|-
 +
|Bobby Orr
 +
|style="background-color:#6b9ac4;|4
 +
|1948
 +
|657
 +
|270
 +
|645
 +
|-
 +
|Wayne Gretzky
 +
|style="background-color:#6b9ac4;|99
 +
|1961
 +
|1487
 +
|894
 +
|1963
 +
|-
 +
|Mario Lemieux
 +
|style="background-color:#6b9ac4;|66
 +
|1965
 +
|915
 +
|690
 +
|1033
 +
|}
  
<nowiki>[ { TEXT("Name") => TEXT("Bobby Orr"),    TEXT("Uniform Number") => VALUE(4),  TEXT("Birth Year") => VALUE(1948), TEXT("Games Played") => VALUE(657),  TEXT("Goals") => VALUE(270), TEXT("Assists") => VALUE(645)  },
+
=====count_if_in_column 3 example=====
  { TEXT("Name") => TEXT("Wayne Gretzky"), TEXT("Uniform Number") => VALUE(99), TEXT("Birth Year") => VALUE(1961), TEXT("Games Played") => VALUE(1487), TEXT("Goals") => VALUE(894), TEXT("Assists") => VALUE(1963) },
+
<code>count_if_in_column(hockey_spreadsheet, 3, is_even)</code> evaluates to '''0'''
  { TEXT("Name") => TEXT("Mario Lemieux"), TEXT("Uniform Number") => VALUE(66), TEXT("Birth Year") => VALUE(1965), TEXT("Games Played") => VALUE(915),  TEXT("Goals") => VALUE(690), TEXT("Assists") => VALUE(1033) } ]</nowiki>
 
  
NOTE: you can assume that you will not be passed the empty list.  If you want to handle this case anyway, raising [https://smlfamily.github.io/Basis/list.html#SIG:LIST.Empty:EXN Empty] seems like a reasonable thing to do.
+
{| class="wikitable"
 +
|Name
 +
|Uniform Number
 +
|Birth Year
 +
|style="background-color:#6b9ac4;|Games Played
 +
|Goals
 +
|Assists
 +
|-
 +
|Bobby Orr
 +
|4
 +
|1948
 +
|style="background-color:#6b9ac4;|657
 +
|270
 +
|645
 +
|-
 +
|Wayne Gretzky
 +
|99
 +
|1961
 +
|style="background-color:#6b9ac4;|1487
 +
|894
 +
|1963
 +
|-
 +
|Mario Lemieux
 +
|66
 +
|1965
 +
|style="background-color:#6b9ac4;|915
 +
|690
 +
|1033
 +
|}
  
 
=Testing=
 
=Testing=

Latest revision as of 19:17, 10 July 2023

Contents

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 Fail "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"</nowiki>

which when run will bind split_path to ["git","425","sml","spreadsheet"]

Spreadsheet

types

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 Fail "NotYetImplemented"

row_count

fun row_count(s : sheet) : int =
        raise Fail "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 Fail "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 Fail "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"), INTEGER(4), INTEGER(1948), INTEGER(657), INTEGER(270), INTEGER(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"), INTEGER(99), INTEGER(1961), INTEGER(1487), INTEGER(894), INTEGER(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"), INTEGER(66), INTEGER(1965), INTEGER(915), INTEGER(690), INTEGER(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 Fail "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 Fail "NotYetImplemented"
column_at(hockey_spreadsheet, 3) example

column_at(hockey_spreadsheet, 3) evaluates to [TEXT("Games Played"), INTEGER(657), INTEGER(1487), INTEGER(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

Functions sum_in_row and sum_in_column are provided. Each invokes sum_in_cell_list which you will implement.

sum_in_cell_list

fun sum_in_cell_list(cells : cell list) : int =
        raise Fail "NotYetImplemented"

Sum the INTEGER cell values.

sum_in_row (Provided)

fun sum_in_row(s : sheet, row_index : int) : int =
        sum_in_cell_list(row_at(s, row_index))
sum_in_row 0 example

sum_in_row(hockey_spreadsheet, 0) evaluates to 0

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
sum_in_row 1 example

sum_in_row(hockey_spreadsheet, 1) evaluates to 3524

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

sum_in_column (Provided)

fun sum_in_column(s : sheet, column_index : int) : int =
        sum_in_cell_list(column_at(s, column_index))
sum_in_column 3 example

sum_in_column(hockey_spreadsheet, 3) evaluates to 3059

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: max

Functions max_in_row and max_in_column are provided. Each invokes max_value_in_cell_list which you will implement.

max_value_in_cell_list

fun max_in_cell_list(cells : cell list) : int option =
        raise Fail "NotYetImplemented"

Evaluate to SOME of the maximum the INTEGER cell, if found. Otherwise evaluate to NONE.

max_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_in_row 0 example

max_in_row(hockey_spreadsheet, 0) evaluates to NONE

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
max_in_row 1 example

max_in_row(hockey_spreadsheet, 1) evaluates to SOME(1948)

Name Uniform Number Birth Year Games Played Goals Assists
Bobby Orr 4 1948 657 270 645
Wayne Gretzky4 99 1961 1487 894 1963
Mario Lemieux 66 1965 915 690 1033

max_in_column (Provided)

fun max_in_column(s : sheet, column_index : int) : int option =
        max_in_cell_list(column_at(s, column_index))
max_in_column 3 example

max_in_column(hockey_spreadsheet, 3) evaluates to SOME(1487)

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: count if

Functions max_in_row and max_in_column are provided. Each invokes max_value_in_cell_list which you will implement.

For the examples we will use this simple function:

fun is_even(cell) = 
    case cell of
           EMPTY => false
    |    TEXT(_) => false
    | INTEGER(v) => (v mod 2) = 0

count_if_in_cell_list

 fun count_if_in_cell_list(cells : cell list, predicate : (cell -> bool)) : int = 
        raise Fail "NotYetImplemented"

Count the number of cells that pass the specified predicate test function.

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_row 0 example

count_if_in_row(hockey_spreadsheet, 0, is_even) evaluates to 0

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
count_if_in_row 1 example

count_if_in_row(hockey_spreadsheet, 1, is_even) evaluates to 3

Name Uniform Number Birth Year Games Played Goals Assists
Bobby Orr 4 1948 657 270 645
Wayne Gretzky4 99 1961 1487 894 1963
Mario Lemieux 66 1965 915 690 1033

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)
count_if_in_column 1 example

count_if_in_column(hockey_spreadsheet, 1, is_even) evaluates to 2

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
count_if_in_column 3 example

count_if_in_column(hockey_spreadsheet, 3, is_even) evaluates to 0

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

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.

SML Error Messages

Pledge, Acknowledgments, Citations

file: studio-spreadsheet-pledge-acknowledgments-citations.txt

More info about the Honor Pledge