*Don't forget to put the statement of sources at the top of your homework!
You don't need to cite the McCarthy or Graham articles.
ASSIGNMENT: Does McCarthy see the primary goal of AI as modeling
human intelligence? Does he think that this goal is achievable? Why
or why not? Summarize some of the key challenges in achieving human-level
(b) 5pts. Write a function (fact n) to return the factorial of the argument n. (The factorial of an integer is the product of all integers from 1 to that integer.) For example, (fact 3) should return 6; (fact 10) should return 3628800. (What do you think (fact 'hello) should return?) Even though there are more efficient methods, you should use recursion to write this function.
(a) 5 pts. Write the function (my-third l) which returns the third element of the list l. Do not use the built-in function (third). You can define this function either recursively or iteratively.
(b) 5 pts. Write the function (scale-by-two l) which takes a list of integers l and returns a list of integers where each element is double the corresponding element in l. Your solution should use a lambda expression. For example, (scale-by-two '(1 2 3 4)) should return (2 4 6 8) and (scale-by-two '(-1 0 1)) should return (-2 0 2).
(c) 15 pts. There are often many different ways to solve the same problem
in Lisp. In this problem, you will need to use your creativity and knowledge
of Lisp functions to write the same function in several different ways. The
function (posint l) should take a list l and return a list
containing only the positive integers in the list. For example, (posint
'(a 2.3 -1 5 hello 3 (1 2)))) should return (5 3 1 2). You
can use the built-in function integerp in your solutions.
Write a function (case? s) that returns the symbol 'upper if the characters in the string s are all upper case, 'lower if the characters are all lower case, and 'mixed if there are some lower case and some upper case letters (or if the string contains any non-letter characters). Hint: first write two subroutines, upper? that tests to see if a string is upper case and lower? that tests to see if a string is lower case. Then use cond with these subroutines to test for which case to return. Useful built-in functions for solving this problem include char, upper-case-p, and lower-case-p.