Difference between revisions of "Dynamic Spreadsheet Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 17: Line 17:
 
=Code To Implement=
 
=Code To Implement=
 
{{RacketToImplement|spreadsheet|to-cell<br>csv->spreadsheet<br>row-count<br>row-at sheet<br>sum-row|spreadsheet}}
 
{{RacketToImplement|spreadsheet|to-cell<br>csv->spreadsheet<br>row-count<br>row-at sheet<br>sum-row|spreadsheet}}
==to-cell==
+
==string->cell==
define a function <code>thunk?</code> which returns whether the specified parameter is a thunk or not.
+
  <nowiki>(define (string->cell s)
 
+
        (error 'not-yet-implemented)) </nowiki>
  <nowiki>(define (thunk? th)
 
    (error 'not-yet-implemented))</nowiki>
 
  
 
==csv->spreadsheet==
 
==csv->spreadsheet==

Revision as of 05:42, 30 March 2022

Motivation

Code To Use

Code To Implement

file: src/main/racket/spreadsheet/spreadsheet.rkt Racket-logo.svg
functions: to-cell
csv->spreadsheet
row-count
row-at sheet
sum-row

string->cell

(define (string->cell s)
        (error 'not-yet-implemented)) 

csv->spreadsheet

define a MACRO thunk-that which takes a parameter e creates thunk. that is: wraps e in a zero argument function.

(define-syntax-rule (thunk-that e)
   (error 'not-yet-implemented))

Thunks are useful for delaying the evaluation of expressions. As such thunk-that must be declared as a macro and not a function. Unlike Haskell which has lazy evaluation, Racket (and most other languages) eagerly evaluates function arguments.

row-count

define a function dethunk which takes a thunk parameter e and returns the result of invoking e.

(define (dethunk-that thunk)
   (error 'not-yet-implemented))

If thunking and expression wraps an expression in a single argument function, then de-thunking is simply calling that function.

If the parameter thunk is not a thunk? then dethunk-that should raise an argument error.

NOTE: It may seem unnecessary to use dethunk-that when implementing Lab4, when you could simply (thunk)... that is "call the thunk". Still, you are encouraged to use dethunk-that as a bit of verbosity can sometimes help in debugging a sea already full of parentheses.

row-at

sum-row

define a function destream which takes a stream parameter and a pair of the next answer and the next stream.

(define (destream stream)
   (error 'not-yet-implemented))

Test

file: spreadsheet_test.rkt Racket-logo.svg Test
source folder: src/test/racket/spreadsheet

note: ensure that you have removed all printing to receive credit for any assignment.