Re: sanity check (coding style)




Brian Downing wrote:
> In article <1133313533.141217.158020@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
> josephoswaldgg@xxxxxxxxxxx <josephoswald@xxxxxxxxx> wrote:

>
> > 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.
>
> (with-output-to-string (*standard-output*) (map nil #'princ v))
>
> Remember, any binding construct with a special variable will make a
> dynamic binding, not just LET and friends.

OW! You made my head hurt. :-)

> You also needn't return the string-stream out of the expression as you
> did above. WITH-OUTPUT-TO-STRING always returns the generated string.
> If it returned the stream you wouldn't get what you wanted.

Not sure what mistake I got that made me think otherwise. I think
reading the CLHS entry bit about the optional argument "string"
confused me.

Still, to get dependable 2-digit results, I'm not sure I like anything
better than
(format t "~2,'0X" e)

> -bcd
> --
> *** Brian Downing <bdowning at lavos dot net>

(defun digest2string (v)
(with-output-to-string (s)
(map nil #'(lambda (e) (format s "~2,'0X" e)) v)))

.



Relevant Pages

  • Re: sanity check (coding style)
    ... > a built-in macro to divert everything destined for a stream (defaulting ... any binding construct with a special variable will make a ... You also needn't return the string-stream out of the expression as you ... If it returned the stream you wouldn't get what you wanted. ...
    (comp.lang.lisp)
  • Re: Wind turbines: Anyone using one now?
    ... The potential power must be ... divert all the flow or is a minimum required to keep the stream flowing. ...
    (uk.local.cumbria)