Differences

This shows you the differences between two versions of the page.

sps [2017/03/26 20:46]
jhemann
sps [2018/10/01 12:20] (current)
joslarki
Line 7: Line 7:
===== Introduction ===== ===== Introduction =====
-Place all of your code in a file named ''bonus.rkt'', and submit it via [[OnCourse]]. +Place all of your code in a file named ''bonus.rkt'', and submit it via [[Canvas]] -- if there's no page for submission, post on piazza.
Make use of the macros and SPS material from class this week, and you might consult the macro tutorials below. Make use of the macros and SPS material from class this week, and you might consult the macro tutorials below.
Line 21: Line 21:
=== Part 1 SPS === === Part 1 SPS ===
-Your task is to transform the functions below into store-passing style such that they have the correct semantics described. **You will remember in class we used ''match-let'' to implement SPS. On your homework, we'll be using [[http://docs.racket-lang.org/reference/values.html?q=values#%28def._%28%28quote._~23~25kernel%29._values%29%29|values]] and [[http://docs.racket-lang.org/reference/let.html?q=let-values#%28form._%28%28quote._~23~25kernel%29._let-values%29%29|let-values]]. These operate similarly.**+Your task is to transform the functions below into store-passing style such that they have the correct semantics described. **To implement SPS, you will use [[http://docs.racket-lang.org/reference/values.html?q=values#%28def._%28%28quote._~23~25kernel%29._values%29%29|values]] and [[http://docs.racket-lang.org/reference/let.html?q=let-values#%28form._%28%28quote._~23~25kernel%29._let-values%29%29|let-values]]. Consult lecture notes or office hours if you forget how these work.**
**1** Recall ''filter'' from [[https://www.cs.indiana.edu/cgi-pub/c311/doku.php?id=assignment-1|assignment 1]]. It would be useful if all of the results removed from the list were also handed back to us. That way, we could ''partition'' the input based on a predicate. Implement ''filter-sps'' that does exactly that. **1** Recall ''filter'' from [[https://www.cs.indiana.edu/cgi-pub/c311/doku.php?id=assignment-1|assignment 1]]. It would be useful if all of the results removed from the list were also handed back to us. That way, we could ''partition'' the input based on a predicate. Implement ''filter-sps'' that does exactly that.
Line 46: Line 46:
    (cond     (cond
      [(null? ls) '()]       [(null? ls) '()]
-      [(pair? (car ls))+      [(list? (car ls))
      (cons (filter* f (car ls)) (filter* f (cdr ls)))]       (cons (filter* f (car ls)) (filter* f (cdr ls)))]
-      [(null? (car ls)) '()] 
      [(f (car ls)) (cons (car ls) (filter* f (cdr ls)))]       [(f (car ls)) (cons (car ls) (filter* f (cdr ls)))]
      [else (filter* f (cdr ls))])))       [else (filter* f (cdr ls))])))
 

sps.1490575618.txt.gz · Last modified: 2017/03/26 20:46 by jhemann