Homework 1 Solutions Part 1 1. There are several possible answers. Here are a couple: -Moving your cursor to the end of an expression and hit enter. -Highlighting the entire expression with the mouse and hitting enter. -Clicking Edit/Select All and hitting enter. -Highlight and copy the expression then paste it in the interaction window and press enter. 2. The return key in MacGambit does not execute expressions. The return key is just a carriage return and will move the cursor down to the next line. Hitting the Enter key, however, would execute the expression and give an error. 3. 3: means that the MacGambit interpreter has encountered three errors since either MacGambit was opened or the error count was cleared. To reset the error count back to zero, hit the apple key+t. 4. It looks like in activity 5 of the first lab, a student mistakenly saved his/her work to the hard drive instead of to a floppy disk. Part 2 Answer to exercise 2.1: NOWHERE (NOW HERE) B BLACKBIRD + BUTFIRST #F (ANY SENTENCE CONTAINING THE WORD THE) (I) PERIHELION Domain error EVERY KEEP VOWEL? Note that the parentheses matter! For example, (I) is different from I. Answer to exercise 2.2: The domain of VOWEL? is anything. (The domain is the set of arguments for which the function is defined--that is, it doesn't give an error--not the set of arguments for which it returns #T.) Answer to exercise 2.3: Domain: APPEARANCES takes two arguments. The second argument can be any word or sentence. If the second argument is a sentence, then the first can be any word. If the second argument is a word, then the first must be a one-letter word. Range: Nonnegative integers. APPEARANCES returns the number of times that the first argument appears as an element of the second (as a word in the sentence, or as a letter in the word). Answer to exercise 2.4: Domain: ITEM takes two arguments. The second can be any nonempty word or sentence. The first must be a positive integer less than or equal to the number of elements in the second argument. Range: Words. (If the second argument is a sentence, then ITEM returns a word. If the second argument is a word, then ITEM returns a one-letter word.) ITEM returns an element of its second argument (a letter of the word, or a word of the sentence) chosen according to the numeric first argument. If the first argument is N, then ITEM returns the Nth element of the second argument. Answer to exercise 2.5: The domain of NUMBER-OF-ARGUMENTS is functions, while the range is numbers. The domain of EVEN? and ODD? is numbers, while their range is Booleans. Answer to exercise 2.6: In addition to the above: FIRST: Domain includes sentences, range is words. LAST: (Ditto). COUNT: Domain includes sentences, range is numbers. ROUND: Domain is all numbers, range is just integers. Also, most of the type predicates, such as NUMBER? and VOWEL?, accept anything as argument, but return only Booleans.