Due at 11:59pm on Friday, 11/09/2018.
Lab Check-in 7 questions here.
By the end of this lab, you should have submitted the lab with
python3 ok --submit. You may submit more than once before the
deadline; only the final submission will be graded.
Check that you have successfully submitted your code on
- To receive credit for this lab, you must complete Questions 1 through 2 in lab11.scm (Questions 2 and 3 on this page) and submit through Ok.
Sign up for checkoffs in your lab if you'd like to get credit for this week's checkoff.
Explain REPL. What are the different stages and what is done in each stage?
Q2: WWSD: Macros
One thing to keep in mind when doing this question, builtins get rendered as so
scm> + #[+] scm> list #[list]
Use Ok to test your knowledge with the following "What Would Scheme Display?" questions:
python3 ok -q wwsd-macros -u
scm> (define-macro (f x) (car x))______fscm> (f (2 3 4)) ; type SchemeError for error, or Nothing for nothing______2scm> (f (+ 2 3))______#[+]scm> (define x 2000)______xscm> (f (x y z))______2000scm> (f (list 2 3 4))______#[list]scm> (f (quote (2 3 4)))______SchemeErrorscm> (define quote 7000)______quotescm> (f (quote (2 3 4)))______7000
scm> (define-macro (g x) (+ x 2))______gscm> (g 2)______4scm> (g (+ 2 3))______SchemeError
scm> (define-macro (if-else-5 condition consequent) `(if ,condition ,consequent 5))______if-else-5scm> (if-else-5 #t 2)______2scm> (if-else-5 #f 3)______5scm> (if-else-5 #t (/ 1 0))______SchemeErrorscm> (if-else-5 #f (/ 1 0))______5scm> (if-else-5 (= 1 1) 2)______2
Q3: Scheme def
def, which simulates a python
def statement, allowing you to write code like
(def f(x y) (+ x y)).
Hint: the previous is equivalent to
(def f (x y) (+ x y)).
Additional hint: use
lambdain your solution.
(define-macro (def func bindings body)'YOUR-CODE-HERE`(define ,func (lambda ,bindings ,body)))
Use Ok to test your code:
python3 ok -q scheme-def