Difference between revisions of "Dynamic Spreadsheet Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
(Created page with "=Motivation= =Code To Use= * [https://docs.racket-lang.org/reference/booleans.html #t] true * [https://docs.racket-lang.org/reference/booleans.html #f] false * [https://docs....")
 
Line 23: Line 23:
 
     (error 'not-yet-implemented))</nowiki>
 
     (error 'not-yet-implemented))</nowiki>
  
===csv->spreadsheet===
+
==csv->spreadsheet==
 
define a '''MACRO''' <code>thunk-that</code> which takes a parameter <code>e</code> creates thunk.  that is: wraps <code>e</code> in a zero argument function.
 
define a '''MACRO''' <code>thunk-that</code> which takes a parameter <code>e</code> creates thunk.  that is: wraps <code>e</code> in a zero argument function.
  
Line 31: Line 31:
 
Thunks are useful for delaying the evaluation of expressions.  As such <code>thunk-that</code> must be declared as a macro and not a function.  Unlike [https://www.haskell.org/ Haskell] which has lazy evaluation, Racket (and most other languages) [https://en.wikipedia.org/wiki/Eager_evaluation eagerly evaluates] function arguments.
 
Thunks are useful for delaying the evaluation of expressions.  As such <code>thunk-that</code> must be declared as a macro and not a function.  Unlike [https://www.haskell.org/ Haskell] which has lazy evaluation, Racket (and most other languages) [https://en.wikipedia.org/wiki/Eager_evaluation eagerly evaluates] function arguments.
  
===row-count===
+
==row-count==
 
define a function <code>dethunk</code> which takes a thunk parameter <code>e</code> and returns the result of invoking <code>e</code>.
 
define a function <code>dethunk</code> which takes a thunk parameter <code>e</code> and returns the result of invoking <code>e</code>.
  
Line 43: Line 43:
 
NOTE: It may seem unnecessary to use <code>dethunk-that</code> when implementing Lab4, when you could simply (thunk)... that is "call the thunk".  Still, you are encouraged to use <code>dethunk-that</code> as a bit of verbosity can sometimes help in debugging a sea already full of parentheses.
 
NOTE: It may seem unnecessary to use <code>dethunk-that</code> when implementing Lab4, when you could simply (thunk)... that is "call the thunk".  Still, you are encouraged to use <code>dethunk-that</code> as a bit of verbosity can sometimes help in debugging a sea already full of parentheses.
  
===row-at===
+
==row-at==
  
===sum-row===
+
==sum-row==
 
define a function <code>destream</code> which takes a <code>stream</code> parameter and a pair of the next answer and the next stream.
 
define a function <code>destream</code> which takes a <code>stream</code> parameter and a pair of the next answer and the next stream.
  
 
  (define (destream stream)
 
  (define (destream stream)
 
     (error 'not-yet-implemented))
 
     (error 'not-yet-implemented))
 
A critical value of this utility function is to provide early error detection.  As such, exceptions should be raised if either
 
 
* the parameter <code>s</code> is not a thunk (this can be handled by <code>dethunk-that</code>)
 
* the result of de-thunking the stream is not a pair
 
* next-stream of the pair is not thunk
 
<!--
 
Example use of  [https://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29 values] and [https://docs.racket-lang.org/reference/define.html?q=define-values#%28form._%28%28quote._~23~25kernel%29._define-values%29%29 define-values]:
 
 
<youtube>iWCcL049dOg</youtube>
 
 
<nowiki>(define (div-mod-values n d)
 
  (values (quotient n d) (modulo n d)))
 
 
(define (printf-div-mod-values n d)
 
  (local [(define-values (q r) (div-mod-values n d))]
 
    (printf "~a/~a => ~a w/ remainder ~a\n" n d q r)))
 
 
(printf-div-mod-values 425 231)</nowiki>
 
 
produces the output:
 
 
<nowiki>425/231 => 1 w/ remainder 194</nowiki>
 
-->
 
===stream-cons-ensuring-stream-prime-is-thunk===
 
Define a function <code>cons-with-thunk-check-on-next-stream</code> which takes two parameters <code>value</code> and <code>next-stream</code>. 
 
 
((define (cons-with-thunk-check-on-next-stream element next-stream)
 
  (error 'not-yet-implemented))
 
 
If the specified <code>next-stream</code> parameter is not a thunk then an error should be raised:
 
 
<code>(raise-argument-error "next-stream" "thunk?" next-stream)</code>
 
 
Do '''NOT''' create a thunk.  If <code>next-stream</code> is a thunk it should simply [https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._cons%29%29 cons] <code>value</code> and <code>next-stream</code>.
 
  
 
=Test=
 
=Test=
 
{{RacketUnitTest|spreadsheet_test|spreadsheet}}
 
{{RacketUnitTest|spreadsheet_test|spreadsheet}}

Revision as of 05:39, 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

to-cell

define a function thunk? which returns whether the specified parameter is a thunk or not.

(define (thunk? th)
    (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.