Difference between revisions of "Deep Lists Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 12: Line 12:
 
{{RacketToImplement|deep_lists|deep-fold<br/>deep-flatten<br/>deep-sum<br/>deep-sum-numbers|deep_lists}}
 
{{RacketToImplement|deep_lists|deep-fold<br/>deep-flatten<br/>deep-sum<br/>deep-sum-numbers|deep_lists}}
 
==Fold==
 
==Fold==
==deep-fold==
+
You can elect to build deep-fold as a higher order function which returns a function which will deep fold left or right depending on which list fold function is passed to it.
  <nowiki>(define (deep-fold list-fold)
+
 
 +
NOTE: You can also elect to just build deep-foldl and/or deep-foldr directly.  If you choose to implement only one of deep-foldl and deep-foldr, be sure to comment out the tests for the unimplemented one.
 +
 
 +
===deep-fold===
 +
  (define (deep-fold list-fold)
 
         (error 'not-yet-implemented))  
 
         (error 'not-yet-implemented))  
  
(define deep-foldl (deep-fold foldl))
+
===deep-foldl===
(define deep-foldr (deep-fold foldr))</nowiki>
+
The provided implementation uses [[#deep-fold]].  You may replace this if you prefer not to implement [[#deep-fold]].
 +
 
 +
(define deep-foldl (deep-fold foldl))
 +
 
 +
===deep-foldl===
 +
The provided implementation uses [[#deep-fold]].  You may replace this if you prefer not to implement [[#deep-fold]].
  
You can elect to build deep-fold as a higher order function which returns a function which will deep fold left or right depending on which list fold function is passed to it.
+
(define deep-foldr (deep-fold foldr))
  
NOTE: You can also elect to just build deep-foldl and/or deep-foldr directly.  If you choose to implement only one of deep-foldl and deep-foldr, be sure to comment out the tests for the unimplemented one.
 
 
==Clients==
 
==Clients==
 
===deep-flatten===
 
===deep-flatten===

Latest revision as of 14:29, 28 March 2022

original inspiration for this warmup comes from Extra Practice Problems

Code To Use

Code To Implement

file: src/main/racket/deep_lists/deep_lists.rkt Racket-logo.svg
functions: deep-fold
deep-flatten
deep-sum
deep-sum-numbers

Fold

You can elect to build deep-fold as a higher order function which returns a function which will deep fold left or right depending on which list fold function is passed to it.

NOTE: You can also elect to just build deep-foldl and/or deep-foldr directly. If you choose to implement only one of deep-foldl and deep-foldr, be sure to comment out the tests for the unimplemented one.

deep-fold

(define (deep-fold list-fold)
       (error 'not-yet-implemented)) 

deep-foldl

The provided implementation uses #deep-fold. You may replace this if you prefer not to implement #deep-fold.

(define deep-foldl (deep-fold foldl))

deep-foldl

The provided implementation uses #deep-fold. You may replace this if you prefer not to implement #deep-fold.

(define deep-foldr (deep-fold foldr))

Clients

deep-flatten

Utilize a version of #deep-fold (and perhaps a list reverse depending on which fold direction you choose) to produce a single flattened list version of the deep list.

For example:

(deep-flatten (list 1 2 (list 3 "fred" 4 5) 6 (list 7 8 (list 9 "george" 10) 11 12)))

should evaluate to

'(1 2 3 "fred" 4 5 6 7 8 9 "george" 10 11 12)

deep-sum

Sums the numbers in a deep list of numbers and lists.

For example:

(deep-sum (list 1 2 (list 3 4 5) 6 (list 7 8 (list 9 10) 11 12)))

should evaluate to 78.

deep-sum-numbers

Like deep-sum only it ignores values which are neither lists nor numbers.

For example:

(deep-sum-numbers (list 1 2 (list 3 "fred" 4 5) 6 (list 7 8 (list 9 "george" 10) 11 12)))

should evaluate to 78.

Test

file: deep_lists_test.rkt Racket-logo.svg Test
source folder: src/test/racket/deep_lists

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