这是一个简单的练习,如果一个list中有几个数字,写一个函数,找出最大值。
(setq number-list '(5 8 9 10 87 34))
(defun max-number(n-list)
(let ((tmp (car n-list)) (max tmp))
(while n-list
(setq tmp (car n-list))
(if (> tmp max)
(setq max tmp)
)
(setq n-list (cdr n-list))
)
max
)
)
(max-number number-list)
结果显示为87.
注意:setq可以用来修改let定义的变量的值。
这里用到了函数定义,局部变量,变量值修改,while循环和if语句,还有>操作符。