Difference between revisions of "Dynamic Spreadsheet Assignment"
Jump to navigation
Jump to search
(12 intermediate revisions by the same user not shown) | |||
Line 18: | Line 18: | ||
* [https://docs.racket-lang.org/reference/strings.html#%28def._%28%28lib._racket%2Fstring..rkt%29._string-suffix~3f%29%29 string-suffix?] | * [https://docs.racket-lang.org/reference/strings.html#%28def._%28%28lib._racket%2Fstring..rkt%29._string-suffix~3f%29%29 string-suffix?] | ||
==list== | ==list== | ||
+ | * [https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._list-ref%29%29 list-ref] returns element of list at position | ||
* [https://docs.racket-lang.org/reference/pairs.html?q=cons#%28def._%28%28quote._~23~25kernel%29._cons%29%29 cons] | * [https://docs.racket-lang.org/reference/pairs.html?q=cons#%28def._%28%28quote._~23~25kernel%29._cons%29%29 cons] | ||
* [https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Fmap..rkt%29._map%29%29 map] | * [https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Fmap..rkt%29._map%29%29 map] | ||
Line 24: | Line 25: | ||
* [https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._reverse%29%29 reverse] | * [https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._reverse%29%29 reverse] | ||
* [https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._length%29%29 length] | * [https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._length%29%29 length] | ||
− | |||
=Code To Implement= | =Code To Implement= | ||
Line 31: | Line 31: | ||
(define (string->cell s) | (define (string->cell s) | ||
(error 'not-yet-implemented)) | (error 'not-yet-implemented)) | ||
+ | |||
+ | * if s is the empty string, evaluate to void | ||
+ | * if s represents a number, evaluate to that number | ||
+ | * if s starts with "(" and ends with ")", evaluate to a form suited for eval | ||
+ | * otherwise, evaluate to s | ||
==csv->spreadsheet== | ==csv->spreadsheet== | ||
(define (csv->spreadsheet matrix) | (define (csv->spreadsheet matrix) | ||
− | (error 'not-yet-implemented)) | + | (error 'not-yet-implemented)) |
+ | |||
+ | given a list of lists of strings, evaluate to a list of list of cells using [[#string->cell]] and a couple of list higher order functions. | ||
==row-count== | ==row-count== | ||
(define (row-count sheet) | (define (row-count sheet) | ||
− | (error 'not-yet-implemented)) | + | (error 'not-yet-implemented)) |
+ | |||
+ | <code>hockey-spreadsheet</code>: | ||
+ | {| 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 | ||
+ | |- | ||
+ | |Mario Lemieux | ||
+ | |66 | ||
+ | |1965 | ||
+ | |915 | ||
+ | |690 | ||
+ | |1033 | ||
+ | |} | ||
+ | |||
+ | <code>('''row-count''' hockey-spreadsheet)</code> evaluates to <code>'''4'''</code> | ||
==row-at== | ==row-at== | ||
(define (row-at sheet row-index) | (define (row-at sheet row-index) | ||
(error 'not-yet-implemented)) | (error 'not-yet-implemented)) | ||
+ | |||
+ | <code>('''row-at''' hockey-spreadsheet 1)</code> evaluates to <code>'''(list "Bobby Orr" 4 1948 657 270 645)'''</code> | ||
+ | |||
==sum-row== | ==sum-row== | ||
(define (sum-row sheet row-index) | (define (sum-row sheet row-index) | ||
(error 'not-yet-implemented)) | (error 'not-yet-implemented)) | ||
+ | |||
+ | <code>('''sum-row''' hockey-spreadsheet 1)</code> evaluates to <code>'''3524'''</code> | ||
+ | |||
+ | <code>function-spreadsheet</code>: | ||
+ | {| class="wikitable" | ||
+ | |<code>(+ 1 2)</code> | ||
+ | |<code>(+ 3 4)</code> | ||
+ | |- | ||
+ | |<code>(/ 10 2)</code> | ||
+ | |<code>(sqrt (/ 1 4))</code> | ||
+ | |- | ||
+ | |<code>(sin (/ 3.14159 4))</code> | ||
+ | |<code>10</code> | ||
+ | |} | ||
+ | |||
+ | <code>('''sum-row''' function-spreadsheet 0)</code> evaluates to <code>'''10'''</code> | ||
+ | |||
+ | <code>('''sum-row''' function-spreadsheet 1)</code> evaluates to <code>'''5 1/2'''</code> | ||
+ | |||
+ | <code>('''sum-row''' function-spreadsheet 2)</code> evaluates to <code>'''10.707106312093558'''</code> | ||
=Test= | =Test= | ||
{{RacketUnitTest|spreadsheet_test|spreadsheet}} | {{RacketUnitTest|spreadsheet_test|spreadsheet}} |
Latest revision as of 14:16, 30 March 2022
Contents
Motivation
Code To Use
general
void
number
string
list
Code To Implement
file: | src/main/racket/spreadsheet/spreadsheet.rkt | |
functions: | string->cell csv->spreadsheet row-count row-at sheet sum-row |
string->cell
(define (string->cell s) (error 'not-yet-implemented))
- if s is the empty string, evaluate to void
- if s represents a number, evaluate to that number
- if s starts with "(" and ends with ")", evaluate to a form suited for eval
- otherwise, evaluate to s
csv->spreadsheet
(define (csv->spreadsheet matrix) (error 'not-yet-implemented))
given a list of lists of strings, evaluate to a list of list of cells using #string->cell and a couple of list higher order functions.
row-count
(define (row-count sheet) (error 'not-yet-implemented))
hockey-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 |
(row-count hockey-spreadsheet)
evaluates to 4
row-at
(define (row-at sheet row-index) (error 'not-yet-implemented))
(row-at hockey-spreadsheet 1)
evaluates to (list "Bobby Orr" 4 1948 657 270 645)
sum-row
(define (sum-row sheet row-index) (error 'not-yet-implemented))
(sum-row hockey-spreadsheet 1)
evaluates to 3524
function-spreadsheet
:
(+ 1 2)
|
(+ 3 4)
|
(/ 10 2)
|
(sqrt (/ 1 4))
|
(sin (/ 3.14159 4))
|
10
|
(sum-row function-spreadsheet 0)
evaluates to 10
(sum-row function-spreadsheet 1)
evaluates to 5 1/2
(sum-row function-spreadsheet 2)
evaluates to 10.707106312093558
Test
file: | spreadsheet_test.rkt | Test |
source folder: | src/test/racket/spreadsheet |
note: ensure that you have removed all printing to receive credit for any assignment.