Re: sanity check (coding style)



Christophe Rhodes <csr21@xxxxxxxxx> writes:

> Michael Naunton <mmn@xxxxxxxxxxxxxxxxxxxxx> writes:
>
>> * (defun to-hex-str (ar)
>> (format nil "~x" (reduce (lambda (a b) (+ (* a 256) b)) ar)))
>>
>> * (to-hex-str #(130 154 235 231 1 41 183 140 144 245))
>>
>> "829AEBE70129B78C90F5"
>
> This is going to look a bit petty, but your function gets the string
> wrong in one sixteenth of the cases, when the first element is less
> than 16 (and so the first hex digit is 0).

Slightly more often than that.

(to-hex-str #(0 0 0 0 0 1 2)) --> "102"

--
__Pascal Bourguignon__ http://www.informatimago.com/
.



Relevant Pages