![]() |
Jupyter at Bryn Mawr College |
|
|
Public notebooks: /services/public/dblank / CS245 Programming Languages / 2016-Fall / Labs |
Due: Thursday, Sept 15, 2016
In the following problems, please define the function, and test it to make sure it works. I have provided a few examples, but you should test your function thoroughly to make sure that it works. That means, add more cells for each problem.
If it doesn't work in some instances, you should demonstrate where it fails. Otherwise, I will assume that you don't know that it fails.
remove-first
takes an item and a list, and removes the first occurrence of item in the list. Finish the code in the next cell, and use the following cells to test that it works. Add additional cells to test more variations, or document where it doesn't work correctly.
# YOUR CODE HERE
raise NotImplementedError()
(remove-first 'a '())
(remove-first 'a '(a))
(remove-first 'a '(a a a))
(remove-first 'a '(b c a))
(remove-first 'a '(a a b c a))
(remove-first 'a '(b c d))
remove-all
takes an item and a list and removes all occurrences of item from the list.
# YOUR CODE HERE
raise NotImplementedError()
(remove-all 'a '())
(remove-all 'a '(a))
(remove-all 'a '(a a a))
(remove-all 'a '(b a c a d a))
remove-nth
takes a number (0-based indexing), an item, and a list. It removes the nth instance of item in the list.
# YOUR CODE HERE
raise NotImplementedError()
(remove-nth 0 'a '(a b a c a d))
(remove-nth 1 'a '(a b a c a d))
(remove-nth 2 'a '(a b a c a d))
substitute
takes an item to search for, an item to replace it, and a list. The function will find all instances of the old item and replace it with the new item.
# YOUR CODE HERE
raise NotImplementedError()
(substitute 'old 'new '())
(substitute 'old 'new '(old))
(substitute 'old 'new '(old old a b c old))
substitute*
works just like substitute
but will find all instances no matter how deeply hidden they are inside sublists of the given list.
# YOUR CODE HERE
raise NotImplementedError()
(substitute* 'old 'new '((old)((((old apple bannan)) (a b c old d e))) old test ((word)) (old) old))
infix->prefix
will convert expressions given in infix notation to prefix notation. It gives an error if you attempt to operate on an empty list.
# YOUR CODE HERE
raise NotImplementedError()
(infix->prefix 1)
(infix->prefix '(1 + 2))
(infix->prefix '((1 + 2) * (8 / 9)))
(infix->prefix '())
eval-infix
will evaluate infix expressions. It should handle +, *, /, and -. It should give an error otherwise.
# YOUR CODE HERE
raise NotImplementedError()
(eval-infix 42)
(eval-infix '(1 + 1))
(eval-infix '(2 * (3 + 7)))
(eval-infix '((8 / 9) * (3 + 7)))
(eval-infix '(1 ^ 1))
The reflection cell is the most import cell in this lab... in all labs. In your reflection, you should:
YOUR ANSWER HERE