gengyangcai
9/27/2015 9:10:00 PM
CL-USER 1 > (defun bad-reverse (lst) (let* ((len (length lst))
(ilimit (truncate (/ len 2)))) (do ((i 0 (1+ i))
(j (1- len) (1- j))) ((>= i ilimit))
(rotatef (nth i lst) (nth j lst)))))
BAD-REVERSE
CL-USER 2 > (setq lst '(a b c))
(A B C)
CL-USER 3 > (bad-reverse lst)
NIL
CL-USER 4 > lst
(C B A)
CL-USER 5 > (setq lst '(a b c))
(A B C)
CL-USER 6 > (good-reverse lst)
(C B A)
CL-USER 7 > lst
(A B C)
CL-USER 8 > (defun good-reverse (lst) (labels ((rev (lst acc)
(if (null lst) acc
(rev (cdr lst) (cons (car lst) acc))))) (rev lst nil)))
GOOD-REVERSE
CL-USER 9 > (reverse lst)
(C B A)
CL-USER 10 > (setq lst (reverse lst))
(C B A)
CL-USER 11 > (nreverse lst)
(A B C)
CL-USER 12 > (setq lst '(a b c))
(A B C)
CL-USER 13 > (nreverse lst)
(C B A)
CL-USER 14 > lst
(A)
CL-USER 15 > (nconc x y)
Error: The variable X is unbound.
1 (continue) Try evaluating X again.
2 Return the value of :X instead.
3 Specify a value to use this time instead of evaluating X.
4 Specify a value to set X to.
5 (abort) Return to level 0.
6 Return to top loop level 0.
Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.
CL-USER 16 : 1 > (setq x (nconc x y))
Error: The variable X is unbound.
1 (continue) Try evaluating X again.
2 Return the value of :X instead.
3 Specify a value to use this time instead of evaluating X.
4 Specify a value to set X to.
5 (abort) Return to level 1.
6 Return to debug level 1.
7 Return to level 0.
8 Return to top loop level 0.
Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.
CL-USER 17 : 2 > (truncate 26.21875)
26
0.21875
CL-USER 18 : 2 > (= (truncate 26.21875) 26)
T
CL-USER 19 : 2 > (multiple-value-bind (int frac) (truncate 26.21875) (list int frac))
(26 0.21875)
CL-USER 20 : 2 > (defun powers (x)
(values x (sqrt x) (expt x 2)))
POWERS
CL-USER 21 : 2 > (multiple-value-bind (base root square) (powers 4)
(list base root square))
(4 2.0 16)
CL-USER 22 : 2 >