How do I convert a decimal number to a list of octal digits in Common Lisp?
问题 I need to have the result in correct order. It works for numbers less than 100 only. (base8 8) gives (1 0) , (base8 20) gives (2 4) , but (base8 100) gives (414) instead of (144) . I tried for 2 days and can not find the problem. Please help me. (defun base8(n) (cond ((zerop (truncate n 8)) (cons n nil)) (t (reverse (cons (mod n 8) (base8 (truncate n 8))))))) 回答1: The problem is that you are reversing the string a few times. The following will do: (defun base8 (n) (let ((t8 (truncate n 8))