Re: sanity check (coding style)
- From: "josephoswaldgg@xxxxxxxxxxx" <josephoswald@xxxxxxxxx>
- Date: 29 Nov 2005 17:18:53 -0800
Sylvain wrote:
> Christophe Rhodes wrote:
> > I'd probably write
> > (defun digest2string (v)
> > (format nil "~{~2,'0X~}" (coerce v 'list)))
>
> ah! this one I like a lot better than my code :-)
> I did play around with coerce but without success
> because I didn't think of using it to turn the
> vector into a list first (thought I could go to
> strings directly, duh)...
>
> thanks!
>
> --Sylvain
You could also do something like,
(defun digest2string (v)
(let ((*print-base* 16))
(with-output-to-string (s)
(map nil #'(lambda (e) (princ e s)) v)
s)))
which shows off some other features, and avoids format line noise, not
that I think that is so bad.
This exercise gives me a surprisingly bad feeling.
1) Format doesn't iterate over general sequences.
2) I originally expected with-output-to-string to capture princ's
output, and tried just
(with-output-to-string (s) (map nil #'princ v) s)
but of course princ still goes to *standard-ouput* without the extra
argument, which requires an anonymous function. I had expected to find
a built-in macro to divert everything destined for a stream (defaulting
to *standard-output*) to a string, then return that string.
.
- Follow-Ups:
- Re: sanity check (coding style)
- From: Brian Downing
- Re: sanity check (coding style)
- From: josephoswaldgg@xxxxxxxxxxx
- Re: sanity check (coding style)
- References:
- sanity check (coding style)
- From: Sylvain
- Re: sanity check (coding style)
- From: Christophe Rhodes
- Re: sanity check (coding style)
- From: Sylvain
- sanity check (coding style)
- Prev by Date: Re: listo-to-hash
- Next by Date: Re: recursion performance
- Previous by thread: Re: sanity check (coding style)
- Next by thread: Re: sanity check (coding style)
- Index(es):