Re: sanity check (coding style)



tar@xxxxxxxxxxxxx (Thomas A. Russ) writes:

> Christophe Rhodes <csr21@xxxxxxxxx> writes:
>
> (defun digest2string (v)
> (with-output-to-string (s)
> (loop for x across v
> do (format s "~2,'0X" x))))
>
>
> This is nice, since it uses the string stream to collect the values. If
> efficiency is really critical, one could avoid the FORMAT call (which
> often tends to be slow) and subsitute a 256 element lookup table:
>
> (defconstant *hex-codes* #("00" "01" ... "FF"))

Surely we don't have to write that by hand; that's not The Lisp Way!

(defconstant *hex-codes* #.(coerce (loop for i from #x00 to #xff collect (format nil "~2,'0x" i)) 'vector))

;-)

-Peter

--
Peter Seibel * peter@xxxxxxxxxxxxxxx
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp * http://www.gigamonkeys.com/book/
.



Relevant Pages

  • Re: sanity check (coding style)
    ... Peter Seibel writes: ... > tar@xxxxxxxxxxxxx (Thomas A. Russ) writes: ... since it uses the string stream to collect the values. ...
    (comp.lang.lisp)
  • Re: sanity check (coding style)
    ... Christophe Rhodes writes: ... >> tar@xxxxxxxxxxxxx (Thomas A. Russ) writes: ... since it uses the string stream to collect the values. ...
    (comp.lang.lisp)
  • Re: Default VK_Enter action in JText* component
    ... Thomas A. Russ, USC/Information Sciences Institute ... //Basic contents of the frame. ... JTextPane inputArea; ...
    (comp.lang.java.gui)
  • Re: Whats so great about lisp?
    ... Addition and subtraction are allowed if the units rationals are =, ... There is a paper about this that was published in Lisp Pointers: ... Thomas A. Russ, USC/Information Sciences Institute ...
    (comp.lang.lisp)
  • Re: style question: FORMAT vs VECTOR-PUSH-EXTEND
    ... the last character is not a substitution, you lose the last bit of ... >> Then just use a hashtable of character substitutions. ... Thomas A. Russ, USC/Information Sciences Institute ...
    (comp.lang.lisp)