(defun variable_arity (a&optional b &rest c) "This is a function which has variable arity" (message (concat"variable a is " a)) (message (concat"variable b is " b)) (if c (message"c is not an empty list") (message"c is an empty list"))) (message"run the fn with 1 variable") (variable_arity"eh") (message"run the fn with 2 variables") (variable_arity"eh""bee") (message"run the fn with 3 variables") (variable_arity"eh""bee""see") (message"run the fn with 4 variables") (variable_arity"eh""bee""see""dee") (message"run the fn with 5 variables") (variable_arity"eh""bee""see""dee""eee")
结果为:
run the fn with 1 variable variable a is eh variable b is c is an empty list run the fn with 2 variables variable a is eh variable b is bee c is an empty list run the fn with 3 variables variable a is eh variable b is bee c is not an empty list run the fn with 4 variables variable a is eh variable b is bee c is not an empty list run the fn with 5 variables variable a is eh variable b is bee c is not an empty list
(defun myfun (a b c d) "This is a nonce function designed to show how to use local variables safely" (let ((e (+ a b)) (f (* c d))) (- e f))) (message (number-to-string (myfun7531)))
输出:
9
递归函数
创建文件:
(defun print_int (n) "This function prints a list of integers in reverse order" (message (number-to-string n)) (if (= n 0) (message"That's all folks!") (print_int (- n 1)))) (print_int5)