Overview
I would certainly appreciate suggestions of other extra credit activities (preferably via email).
It was a challenging exam and most of you did quite well. Congratulations!
When you get your exam back you’ll see notes at the top.
The examples section is important! Try a few cases to show yourself and me that your procedure works!
Note: Helpers often make design user. Remember: “Uh stands for “use helpers””
Sam talked about this header while stepping through it.
#lang racket
(require loudhum)
(require 2htdp/image)
;; SAMR SAYS: I will preface all of my comments two semicolons, a space,
;; and the words "SAMR SAYS".
;;; File:
;;; 000000.rkt
;;; Authors:
;;; The student currently referred to as 000000
;; SAMR SAYS: You should have changed the 000000's. Reading instructions
;; is important.
;;; Jo Smith
;; SAMR SAYS: You may lose points for making your exam non-anonymous.
;;; Contents:
;;; Code and solutions for Exam 1 2019S
;;; Citations:
;;;
;; +---------+--------------------------------------------------------
;; | Grading |
;; +---------+
;; This section is for the grader's use. Please do not remove it.
;; Problem 1: 11
;; Problem 2: 8
;; Problem 3: 7
;; Problem 4: 10
;; Problem 5: 6
;; Problem 6: 9
;; ----
;; Total: 51/60
;; Scaled: 85/100
;; Errors: 4
;; Times: 2
;; 000000: -1
;; Won't run: -2
;; :
;; ----
;; Total: 58/100 -> 67/100 with TMTL
;; +----------+-------------------------------------------------------
;; | Prologue |
;; +----------+
; Time Log:
; Date Start Finish Elapsed Activity
; 2019-02-25 08:00 09:00 1:00 Enjoyed reading problems
; 2019-02-25 18:00 18:15 0:15 Emailed prologue to sam
; Time Spent: 1:15
sublist and string-reverse;;; Procedure:
;;; sublist
;;; Parameters:
;;; lst, a list
;;; start, a number
;;; end, a number
;;; Purpose:
;;; Pulls the sublist from a list that starts at start and ends
;;; at end.
;;; Produces:
;;; sub, a list
;;; SAMR SAYS: name, type
;;; Preconditions:
;;; * start >= 0
;;; * 0 <= end <= (length lst)
;;; * start <= end
;;; * lst can't be empty (or maybe it can if start and end are 0)
;;; * start and end must be exact integers
;;; Postconditions:
;;; * sub is a sublist of lst.
;;; * start and end help specify that sublist.
;;; * element 0 of sub is element start of lst
;;; * element 1 of sub is element start+1 of lst
;;; * element 2 of sub is element start+2 of lst
;;; * ...
;;; * (length sub) = (- end start)
Simplified preconditions:
;;; * 0 <= start <= end <= (length lst)
Tradeoff between parameters and the preconditions
;;; Parameters:
;;; start, a non-negative exact integer
;;; (now our preconditions need not state that)
;;; Parameters:
;;; start, a non-negative exact integer less than finish
Mathy postconditions
;;; Postconditions:
;;; For all i, 0 <= i < (length sub)
;;; (list-ref sub i) = (list-ref lst (+ start i))
lst, start
and end, and not a, b, and c, and certainly not num, str,
and lst. (Also not :-/, /-: and ///\\\\\\.;;; Procedure:
;;; string-reverse
;;; Parameters:
;;; str, a string
;;; Purpose:
;;; Reverses a string
;;; Produces:
;;; reversed, a string
;;; Preconditions:
;;; str must be nonempty
;;; Postconditions:
;;; For all i, 0 <= i < (string-length str)
;;; character i in reversed is character length-i-1 in str
A clever but not sufficient postconditions
;;; (string-reverse reversed) = str
(define string-reverse
(lambda (str)
str))
; Thought process:
; Start with a backtick
; lots of not-backticks
; End with a backtick
(define markdown-code
(lambda (str)
(regexp-replace* #px"`([^`]*)`"
str
"<code>\\1</code>")))
> (markdown-code "I wrote `markdown-code`.")
"I wrote <code>markdown-code</code>."
> (markdown-code "`markdown-code` takes one parameter, `str`.")
"<code>markdown-code</code> takes one parameter, <code>str</code>."
> (markdown-code "Here's a backtick: `.")
"Here's a backtick: `."
; Thought process for emphasis.
; _ for em is a lot like ` for code
(define markdown-em
(lambda (str)
(regexp-replace* #px"_([^_]*)_"
str
"<em>\\1</em>")))
A shorter version
(define markdown-em
(section regexp-replace* #px"_([^_]*)_" <> "<em>\\1</em>"))
What about two underscores? It feels similar.
(define markdown-strong
(lambda (str)
(regexp-replace* #px"__([^__]*)__"
str
"<strong>\\1</strong>")))
What is #px"[ab]"? a or b
What is #px"[^ab]"? Anything one character that’s not a or b.
What is #px"[^__]"? Anything that’s not underscore. (The goal was
likely “not two underscores”, but set notation does not work for that.)
Here’s a likely pattern for “not two underscores”: #px"(([^_]|_[^_])*)"
How do we combine the two?
(define markdown-emphasis
(o markdown-em
markdown-strong))