On this page:
1 Toilets
2 Accumulators
8.5

Lecture 25: Accumulators

This assignment is due on Sunday, April 10 at 11:59pm. Submit it using Handin as assignment lecture25.

1 Toilets

Exercise 1. Read All smart contracts are ambiguous by Grimmelmann. Focus on common assumptions that Grimmelmann calls into question.
  • When you follow the link above with your browser, you should see Grimmelmann’s article, as well as a button “<” in the upper-right corner. Use the “<” button to expand the annotation sidebar.

  • You may need to log in to Hypothesis, using the account you created in Lecture 5: The table method.

  • Expand the drop-down menu “Public” in the sidebar, and change it to our course group “211”. You belong to this group because you used the invite link in Lecture 5: The table method. If you don’t post to this group, then other students won’t see your annotations, and you won’t get credit.

  • Find a complete sentence where Grimmelmann writes something he doesn’t mean. Carefully select it, and Annotate it like this:
    • Here Grimmelmann writes that ….

    • But I think he doesn’t mean that ….

    • My evidence is that ….

    For example, on page 3, it would be correct to annotate the sentence “smart contracts are not” as follows:
    • Here Grimmelmann writes that smart contracts are not ambiguous.

    • But I think he doesn’t mean that smart contracts are not ambiguous.

    • My evidence is that the title of the article is “All smart contracts are ambiguous.”

    In contrast, on page 8, it would be incorrect to annotate “just transfer resources” as follows, because that is not a complete sentence:
    • Here Grimmelmann writes that these transactions just transfer resources.

    • But I think he doesn’t mean that these transactions just transfer resources.

    • My evidence is that he writes “they can create and execute computer programs.”

    Also, on page 15, it would be incorrect to annotate “But is the oracle correct?” as follows, because that question does not say that the oracle is correct:
    • Here Grimmelmann writes that the oracle is correct.

    • But I think he doesn’t mean that the oracle is correct.

    • My evidence is that he writes “the oracle software has no unmediated access to the truth”.

  • Find one place in the article where you were confused, uncertain, or curious. Carefully select exactly the relevant passage, and Annotate it with your question and what you have done towards answering it.
    • Make your question clear, descriptive, and specific.

    • Don’t be too brief, terse, or vague. Don’t just say “What’s this” or “I don’t understand”.

    • Don’t just summarize.

  • Once you have added your annotations, respond to someone else.

  • Don’t bullshit.

Optional: learn more about zero-knowledge proofs, a mainstay of modern cryptography that underpins blockchains and smart contracts.

2 Accumulators

Exercise 2. Finish designing the following function. Do not use the built-in function reverse.
; rev : [ListOf X] -> [ListOf X]
; reverses the order of elements in the given list
(check-expect (rev empty) empty)
(check-expect (rev (list "man" "bites" "dog")) (list "dog" "bites" "man"))
(check-expect (rev (list       "bites" "dog")) (list "dog" "bites"))
(check-expect (rev (list               "dog")) (list "dog"))
Hint: fill in the list-processing template using the wishlist method.

Exercise 3. What’s the cumulative distance to Andrew station? Define it as a constant named ashmont-andrew.

The code written in the video above is available for your reference. To download it, don’t use “Save Page As” or “Save As”; use “Save Link As” or “Download Linked File” in your Web browser. If you can’t find the command, try right-clicking or two-finger-tapping or long-pressing.

Exercise 4. Finish designing this function using the accumulator:
; sum : [ListOf Number] -> Number
; returns the sum of the given numbers
(define (sum lon) (sum/a lon 0))
(check-expect (sum empty) 0)
(check-expect (sum (list 10 20 50)) 80)
 
; sum/a : [ListOf Number] Number -> Number
; returns the sum of the given numbers
; *Accumulator*: total is the sum of numbers seen so far
(define (sum/a lon total) ...)
Hint: Write sequences of examples and follow the template for processing a list. But if your recursive call looks like (sum/a (rest lon) total), then it is incorrect because it does not update the accumulator according to the accumulator statement.

Optional: Read Chapters 31–32 and 34 of the textbook.