CMPU-145, Spring 2013 Lab 1 Instructions Feb. 4, 2013 Create a directory for this lab within your own CS account. Be sure to download the asmt-helper.txt file and the lab1-template.txt file. Open up the lab1-template.txt file in drscheme. Use the "Save As" menu item to give your lab1-template.txt file a new name that includes your last name (e.g., obama-lab1-defns.txt). Note that it includes a LOAD expression that loads the file asmt-helper.txt, as in lab0. PROBLEM 0. Consider the following definitions: (define item 1) (define listy '(1 2)) Write the following tester expressions into your definitions window: (tester '(cons item listy)) (tester '(cons item item)) (tester '(cons listy item)) (tester '(cons listy listy)) Look at the results. Note that expressions such as "(1.1)" are called "dotted lists". They do not represent well-formed lists. Write similar expressions for the built-in LIST and APPEND functions. Comment out the expressions that cause an error. Be sure you understand all of the results. PROBLEM 1. Enter all of the following TESTER expressions into your definitions window. Before hitting the RUN button, guess what the results will be. (tester '(map even? '(1 2 3 4 5))) (tester '(map (lambda (x) (* x x)) '(1 2 3 4 5))) (tester '(map first '((1 2 3) (4 5) (6 7 8 9)))) (tester '(map rest '((1 2 3) (4 5) (6 7 8 9)))) (tester '(map (lambda (subbie) (list (first subbie) (second subbie))) '((1 2 3) (4 5) (6 7 8 9)))) Define a function, called TRICKY, that satisfies the following contract: ;;; TRICKY ;;; ----------------------------------------- ;;; INPUTS: ITEM, an item ;;; LOL, a list of lists ;;; OUTPUT: A list-of-lists just like LOL, except that each ;;; subsidiary list has been prepended with ITEM. > (tricky 1 '((2 3) (4 5 6) (8 9))) ((1 2 3) (1 4 5 6) (1 8 9)) HINT: Use an expression of the form: (map (lambda (subbie) ...)) as in the last of the above examples. However, the body of the lambda function will have to be different. Should you use CONS, LIST or APPEND?! PROBLEM 2. Type the following TESTER expression into your definitions window. Before hitting the RUN button, guess what the result will be. (tester '(let* ((x 2) (y (* x x)) (z (+ x y)) (w (* z 10))) (list x y z w))) Create a function, called FUNKY, that satisfies the following contract. ;;; FUNKY ;;; ----------------------------------------- ;;; INPUT: LISTY, a list of integers ;;; SIDE EFFECT: Prints out LISTY-ONE, LISTY-TWO and LISTY-THREE ;;; where LISTY-ONE is the same as LISTY except that each ;;; number has been incremented by one; ;;; LISTY-TWO is the same as LISTY-ONE except that ;;; each element has been squared; ;;; LISTY-THREE is a list of booleans: #t if the ;;; corresponding element of LISTY-TWO is even, ;;; #f otherwise. ;;; OUTPUT: LISTY-THREE Example: > (funky '(1 2 3)) listy-one: (2 3 4) listy-two: (4 9 16) listy-three: (#t #f #t) (#t #f #t) <----- output value Note: You may wish to use PRINTF to print out lists, as illustrated below: (printf "mylist: ~A~%" '(1 2 3 4)) Note: Use LET* to generate the sequence of lists. For each one, use a MAP expression! ===================================================== When your functions are working properly, ask me or a coach to come over to check your work. Before submitting electronically, hit the RUN button one last time. Then save your interactions into a file by using the "Save Other" menu item, and then selecting "Save Interactions As Text". Next, go to the terminal window. Make sure you are in the parent directory, looking at your lab1 directory. (Ask for help if you don't know what this means.) Then submit your directory using submit145. submit145 lab1 YOUR-LAB1-DIRECTORY Let us know if it doesn't seem to work. ===> You do not need to print out anything for this and any future lab.