;; ===================================================================================== ;; _____ __ __ ____ _ __ __ ____ ___ ;; / ____/ |/ / __ \/ / / / < / __ < / Spring 2019 Section 54 ;; / / / /|_/ / /_/ / / / /_____/ / / / / / ;; / /___/ / / / ____/ /_/ /_____/ / /_/ / / Quiz 2 ;; \____/_/ /_/_/ \____/ /_/\____/_/ Friday, 15th February, 2019 ;; ;; .d8888. .d88b. db db db d888888b d888888b .d88b. d8b db .d8888. ;; 88' YP .8P Y8. 88 88 88 `~~88~~' `88' .8P Y8. 888o 88 88' YP ;; `8bo. 88 88 88 88 88 88 88 88 88 88V8o 88 `8bo. ;; `Y8b. 88 88 88 88 88 88 88 88 88 88 V8o88 `Y8b. ;; db 8D `8b d8' 88booo. 88b d88 88 .88. `8b d8' 88 V888 db 8D ;; `8888Y' `Y88P' Y88888P ~Y8888P' YP Y888888P `Y88P' VP V8P `8888Y' ;; ;; ===================================================================================== *** QUESTION 1 *** [ 3 points ] The function FOO as given will display side-effect printing as follows: 3 times 7 is (* x y) The key to this question is the presence of the ' character, representing the QUOTE function. Recall that this function shields the next complete expression, either a symbol or a list, from evaluation so that Scheme treats it is 'as is'. *** QUESTION 2 *** [ 4 points ] Predicates are used for determining the truth of a statement. Predicates always output TRUE or FALSE (#t or #f). Types of predicates include those which check the type of a datum (e.g. SYMBOL?, PROCEDURE?) and those which check for (in)equality (e.g. =, >=, EQ?). *** QUESTION 3 *** [ 4 points ] There are numerous examples, including (but not limited to): SYMBOL? NULL? EQ? < PROCEDURE? NUMBER? = > INTEGER? FUNCTION? >= STRING? BOOLEAN? VOID? <= LIST? *** QUESTION 4 *** [ 4 points ] The function THE-SAME? compares two symbols; if they are the same, it outputs the symbol YES, else it outputs NO. (define the-same? (lambda (one two) (if (eq? one two) 'YES 'NO))) 1. It is important to use EQ? here, not =, as this function compares *any type of symbol* and not numbers only. (1 point.) 2. As the function outputs symbols, the QUOTE function (or ') should be used. Side-effect printing (with PRINTF) is not used here. 3. YES and NO should be in the correct places. 4. Either IF or COND may be used (though IF is the more logical choice); if COND is used, there must be an ELSE. 5. ELSE is not used with IF. (It is implied by the design of the function.) [ / 15 ]