Common Lisp 练习题 1
Table of Contents
1 p Exercise 1.1 [m]
Define a version of 1a s t -name that handles "Rex Morgan MD," "Morton Downey, Jr.," and whatever other cases you can think of.
(setf name1 '(Rex Morgan MD\,))
2 p Exercise 1.2 [m]
Write a function to exponentiate, or raise a number to an integer power. For example: (power 3 2 ) = 32 = 9.
(defun power(num mul-times)
3 p Exercise 1.3[m]
Write a function that counts the number of atoms in an expression. For example: ( count - a toms ' ( a ( b ) c ) ) = 3. Notice that there is something of an ambiguity in this: should ( a ni 1 c ) count as three atoms, or as two, because it is equivalent to ( a nil c ) ?
4 Exercise 1.4 [m]
Write a function that counts the number of times an expression occurs anywhere within another expression. Example: ( count - anywhere ' a ' ( a ( ( a ) b ) a ) ) 3.
(defun count-anywhere (item tree)
5 Exercise 1.5 [m]
Write a function to compute the dot product of two sequences of numbers, represented as lists. The dot product is computed by multiplying corresponding elements and then adding up the resulting products. Example:
(dot-product '(10 20) ' ( 3 4 ) ) = 10 x 3 + 20 x 4 = 110
(defun dot-product(f-list s-list)
Render by hexo-renderer-org with Emacs 25.1.1 (Org mode 9.0.2)