Pages

Friday, September 11, 2009

Some notes working with Common Lisp

1. When using multiple-value-bind, there are some values that we don't need. We can ignore the warning "The variable x, y,... is never used...". Below is an example:
(defun my-round (x)
(round (+ x 0.5)))

(defun next-power-of-two (x)
(let ((log-base2 (/ (log x) (log 2))))
(multiple-value-bind (y z)
(my-round (expt 2 (ceiling log-base2)))
(declare (ignorable z))
y)))
Because the my-round functions returns two values, but I only use the first one. When I apply this function inside the next-power-of-two function, I also need the first.

2. In order to use the hexadecimal values in Common Lisp, we can use "#x" or "x16r" to represent them.

1 comment: