Extra Homework 3

Due by 11:59pm on Wednesday, December 4

Instructions

Download extra03.zip. Inside the archive, you will find a file called , along with a copy of the Ok autograder.

Submission: When you are done, submit with python3 ok --submit. You may submit more than once before the deadline; only the final submission will be scored.

Using Ok

The ok program helps you test your code and track your progress. The first time you run the autograder, you will be asked to log in with your @berkeley.edu account using your web browser. Please do so. Each time you run ok, it will back up your work and progress on our servers. You can run all the doctests with the following command:

python3 ok

To test a specific question, use the -q option with the name of the function:

python3 ok -q <function>

By default, only tests that fail will appear. If you want to see how you did on all tests, you can use the -v option:

python3 ok -v

If you do not want to send your progress to our server or you have any problems logging in, add the --local flag to block all communication:

python3 ok --local

When you are ready to submit, run ok with the --submit option:

python3 ok --submit

Readings: You might find the following references useful:

Alternative

If you enter the Scheme Recursive Art Contest or the 61A Project Fair (with a submission that demonstrates reasonable effort or creativity), then you can skip this extra homework assignment.

No Ok

There are no ok tests for this question. You'll need to test your code by placing the logic interpreter into your Scheme project directory and then running python3 e09.py extra03.logic and inspecting the result. It's fine if you produce the correct outputs in a different order than the description below.

Q1: Eval

Implement the eval relation, which relates an addition relation to its value. An addition relation is either a number from 1 to 5 or a three-element relation (+ _ _) where the blanks are addition relations.

logic> (query (eval (+ 1 2) 2))
Failure.

logic> (query (eval (+ 1 2) 3))
Success!

logic> (query (eval (+ 1 2) ?val))
Success!
val: 3

logic> (query (eval (+ 2 (+ 1 1)) ?val))
Success!
val: 4

logic> (query (eval ?exp 4))
Success!
exp: 4
exp: (+ 1 3)
exp: (+ 1 (+ 1 2))
exp: (+ 1 (+ 1 (+ 1 1)))
exp: (+ 1 (+ 2 1))
exp: (+ 1 (+ (+ 1 1) 1))
exp: (+ 2 2)
exp: (+ 2 (+ 1 1))
exp: (+ (+ 1 1) 2)
exp: (+ (+ 1 1) (+ 1 1))
exp: (+ 3 1)
exp: (+ (+ 1 2) 1)
exp: (+ (+ 1 (+ 1 1)) 1)
exp: (+ (+ 2 1) 1)
exp: (+ (+ (+ 1 1) 1) 1)