From: Ken Tilton
Subject: format line wrap?
Date: 
Message-ID: <UsADi.21$vN5.12@newsfe12.lga>
I am stuck on one of my homework problems, viz. using format to wrap a 
long string into a block of lines at, say, 40 columns. My instructor 
does not read c.l.l, so can someone help me?

I coulda swore I saw an example here in the past month, but my carpal 
tunnel collapsed clicking all over the frickin CLHS and I never saw 
anything promising.

kt

-- 
http://www.theoryyalgebra.com/

"We are what we pretend to be." -Kurt Vonnegut

From: Thomas A. Russ
Subject: Re: format line wrap?
Date: 
Message-ID: <ymizm01ezh1.fsf@blackcat.isi.edu>
Ken Tilton <···········@optonline.net> writes:

> I am stuck on one of my homework problems, viz. using format to wrap a
> long string into a block of lines at, say, 40 columns. My instructor
> does not read c.l.l, so can someone help me?
> 
> I coulda swore I saw an example here in the past month, but my carpal
> tunnel collapsed clicking all over the frickin CLHS and I never saw
> anything promising.

Ha, ha.

-- 
Thomas A. Russ,  USC/Information Sciences Institute

(defun wrap-long-string (long-string column-width)
  (let ((cw (list column-width)))
    (setf (cdr cw) cw)
    (format nil "~{~<~%~1,v:;~a~>~^ ~}"
           (mapcan #'list cw (split-sequence long-string #\Space)))))
From: Carl Taylor
Subject: Re: format line wrap?
Date: 
Message-ID: <w_ADi.493242$p47.439616@bgtnsc04-news.ops.worldnet.att.net>
Ken Tilton wrote:
> I am stuck on one of my homework problems, viz. using format to wrap a
> long string into a block of lines at, say, 40 columns. My instructor
> does not read c.l.l, so can someone help me?


(let ((prime-factors (make-list 100 :initial-element 9)))
  (format t "~2%~2T~:D has ~D prime factors:~2%~
                 ~2T~{~<~%~2T~10:;~:D~>~^ - ~}.~3%"
               99999999999999999999
               35
               prime-factors))


Fool around with the ~10:; in the third line to get the width you want.  This 
number is the number of spaces left as the right margin.

hth
clt
From: Ken Tilton
Subject: Re: format line wrap?
Date: 
Message-ID: <UMBDi.919$DR3.285@newsfe12.lga>
Carl Taylor wrote:
> Ken Tilton wrote:
> 
>> I am stuck on one of my homework problems, viz. using format to wrap a
>> long string into a block of lines at, say, 40 columns. My instructor
>> does not read c.l.l, so can someone help me?
> 
> 
> 
> (let ((prime-factors (make-list 100 :initial-element 9)))
>  (format t "~2%~2T~:D has ~D prime factors:~2%~
>                 ~2T~{~<~%~2T~10:;~:D~>~^ - ~}.~3%"
>               99999999999999999999
>               35
>               prime-factors))
> 
> 
> Fool around with the ~10:; in the third line to get the width you want.  
> This number is the number of spaces left as the right margin.

Carl, yer a genius. Again, I saw that ; and knew it was not what I 
wanted. The long string version (requires split-sequence):

(let ((*print-right-margin* 30)
       (words (split-sequence #\space
                (delete #\newline
                  "Four score and seven years ago our fathers brought
forth on this continent a new nation conceived in liberty and
dedicated to the proposition that most people like sports bars."))))
  (format t "~2%~2T~{~<~%~2T~10:;~:a~>~^ ~}~3%" words))

->
   Four score and
   seven years ago
   our fathers
   brought forth on
   this continent a
   new nation
   conceived in
   liberty and
   dedicated to the
   proposition that
   most people like
   sports bars.


Thx, I'm gettin an A on this one!!!

kenny

-- 
http://www.theoryyalgebra.com/

"We are what we pretend to be." -Kurt Vonnegut
From: Carl Taylor
Subject: Re: format line wrap?
Date: 
Message-ID: <SVCDi.493585$p47.99803@bgtnsc04-news.ops.worldnet.att.net>
"Ken Tilton" <···········@optonline.net> wrote in message 
······················@newsfe12.lga...

> ..... The long string version (requires split-sequence):
>
> (let ((*print-right-margin* 30)
>       (words (split-sequence #\space
>                (delete #\newline
>                  "Four score and seven years ago our fathers brought
> forth on this continent a new nation conceived in liberty and
> dedicated to the proposition that most people like sports bars."))))
>  (format t "~2%~2T~{~<~%~2T~10:;~:a~>~^ ~}~3%" words))


Very interesting! I can find <split-sequence> in the LW "lispworks" package, but 
can't find it in the documentation.

Text strings can be wrapped in an "empty" <format> for decent alignment, and 
<unwind-protect (values)> kills that ugly nil at the end.

clt


CL-USER 48 >

(let ((*print-right-margin* 90))
  (unwind-protect
      (values)
    (format t "~2%~6T~{~<~%~6T~65:;~:a~>~^ ~}~3%"
               (split-sequence
                  '(#\Space)
                  (format nil
                              "Four score and seven years ago ~
                               our fathers brought forth on this ~
                               continent a new nation conceived ~
                               in liberty and dedicated to the ~
                               proposition that most people like ~
                               sports bars.")))))


      Four score and seven years ago
      our fathers brought forth on this
      continent a new nation conceived
      in liberty and dedicated to the
      proposition that most people like
      sports bars.



CL-USER 49 >
From: Rob Warnock
Subject: Re: format line wrap?
Date: 
Message-ID: <X9idnZWScfLCIkLbnZ2dnUVZ_qPinZ2d@speakeasy.net>
Ken Tilton  <·········@gmail.com> wrote:
+---------------
| (let ((*print-right-margin* 30)
|        (words (split-sequence #\space
|                 (delete #\newline
|                   "Four score and seven years ago our fathers brought
| forth on this continent a new nation conceived in liberty and
| dedicated to the proposition that most people like sports bars."))))
|   (format t "~2%~2T~{~<~%~2T~10:;~:a~>~^ ~}~3%" words))
| 
| ->
|    Four score and
|    seven years ago
|    our fathers
|    brought forth on
|    this continent a
|    new nation
|    conceived in
|    liberty and
|    dedicated to the
|    proposition that
|    most people like
|    sports bars.
+---------------

That one didn't work for me on CMUCL, I got this output instead:

  Four score and seven years ago our fathers broughtforth on this 
  continent a new nation conceived in liberty anddedicated to the 
  proposition that most people like sports bars.

But when I changed the "~10:;" in the format to "~40:;", I got this:

  Four score and seven years ago our 
  fathers broughtforth on this continent 
  a new nation conceived in liberty 
  anddedicated to the proposition that 
  most people like sports bars.

It looks like CMUCL's ignoring *PRINT-RIGHT-MARGIN* or something...


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Carl Taylor
Subject: Re: format line wrap?
Date: 
Message-ID: <3IBDi.493342$p47.172457@bgtnsc04-news.ops.worldnet.att.net>
"Carl Taylor" <··········@att.net> wrote in message 
····························@bgtnsc04-news.ops.worldnet.att.net...
> Ken Tilton wrote:
>> I am stuck on one of my homework problems, viz. using format to wrap a
>> long string into a block of lines at, say, 40 columns. My instructor
>> does not read c.l.l, so can someone help me?
>
>
> (let ((prime-factors (make-list 100 :initial-element 9)))
>  (format t "~2%~2T~:D has ~D prime factors:~2%~
>                 ~2T~{~<~%~2T~10:;~:D~>~^ - ~}.~3%"
>               99999999999999999999
>               35
>               prime-factors))


Oops, you want a string!

clt

CL-USER 14 >
(format t "~2%~2T~{~<~%~2T~50:;~C~>~}~3%"
           (make-list 500 :initial-element #\X))


  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


NIL
From: Daniel Leidisch
Subject: Re: format line wrap?
Date: 
Message-ID: <87tzq9xbe1.fsf@zeus.home>
Ken Tilton <···········@optonline.net> writes:

> I am stuck on one of my homework problems, viz. using format to wrap a
> long string into a block of lines at, say, 40 columns. My instructor
> does not read c.l.l, so can someone help me?
>
> I coulda swore I saw an example here in the past month, but my carpal
> tunnel collapsed clicking all over the frickin CLHS and I never saw
> anything promising.

After much googling, I decided to cheat (but I do use /format/,
and... ahem... a little loop):

(format t "~{~<~%~1,40:;~A~>~}"
        (loop for x across
             *a-string*
             collect x))

But it works, and I understand it, so I learned something. ;)


regards,

dhl
From: Daniel Leidisch
Subject: Re: format line wrap?
Date: 
Message-ID: <87y7flvvzp.fsf@zeus.home>
Daniel Leidisch <····@leidisch.net> writes:

> Ken Tilton <···········@optonline.net> writes:


> After much googling, I decided to cheat (but I do use /format/,
> and... ahem... a little loop):
>
> (format t "~{~<~%~1,40:;~A~>~}"
>         (loop for x across
>              *a-string*
>              collect x))
>

That's better:

(format t "~{~<~%~,40:;~A~>~}"
                 (loop for x across
                      *a-string*
                      collect x))

regards,

dhl
From: Ken Tilton
Subject: Re: format line wrap?
Date: 
Message-ID: <acEDi.946$DR3.928@newsfe12.lga>
Daniel Leidisch wrote:
> Daniel Leidisch <····@leidisch.net> writes:
> 
> 
>>Ken Tilton <···········@optonline.net> writes:
> 
> 
> 
>>After much googling, I decided to cheat (but I do use /format/,
>>and... ahem... a little loop):
>>
>>(format t "~{~<~%~1,40:;~A~>~}"
>>        (loop for x across
>>             *a-string*
>>             collect x))
>>
> 
> 
> That's better:
> 
> (format t "~{~<~%~,40:;~A~>~}"
>                  (loop for x across
>                       *a-string*
>                       collect x))

How about some sample output? (hint)

:)

kt

-- 
http://www.theoryyalgebra.com/

"We are what we pretend to be." -Kurt Vonnegut
From: Daniel Leidisch
Subject: Re: format line wrap?
Date: 
Message-ID: <87tzq8wxma.fsf@zeus.home>
Ken Tilton <···········@optonline.net> writes:

>> That's better:
>>
>> (format t "~{~<~%~,40:;~A~>~}"
>>                  (loop for x across
>>                       *a-string*
>>                       collect x))
>
> How about some sample output? (hint)

Hm, I think I'm a little lost...

CL-USER> (defparameter *a-string* (make-string 100 :initial-element #\x))
*A-STRING*
CL-USER> (format t "~{~<~%~,10:;~A~>~}"
                 (loop for x across
                      *a-string*
                      collect x))

xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
NIL

CL-USER> (setq *a-string* "The quick brown fox jumps over the lazy dog.")
"The quick brown fox jumps over the lazy dog."
CL-USER> (format t "~{~<~%~,5:;~A~>~}"
                 (loop for x across
                      *a-string*
                      collect x))

The q
uick 
brown
 fox 
jumps
 over
 the 
lazy 
dog.
NIL

What is wrong? Maybe it's something *really* stupid again, but I don't
get it. Is it because it returns nil? That would not be a problem,
would it?

CL-USER> (defparameter *string*
           (make-array 0 
                       :element-type 'character
                       :fill-pointer 0
                       :adjustable t))
*STRING*
CL-USER> (defparameter *wrapped-string*
           (make-array 0 
                       :element-type 'character
                       :fill-pointer 0
                       :adjustable t))
*WRAPPED-STRING*
CL-USER> (with-output-to-string (string *wrapped-string*)
           (format string "~{~<~%~,5:;~A~>~}"
                   (loop for x across
                        *a-string*
                        collect x))
           *wrapped-string*)
"The q
uick
 bro
wn f
ox j
umps
 ove
r th
e la
zy d
og."

I see, it's not very elegant, but doesn't it do what it's supposed
to? Well, I didn't test all possible cases, and I'm already pretty
tired... I guess you'll have to show yet another humble dilettante
the path to enlightenment. ;)

regards,

dhl

p.s.

I recently checked out cells in order to have something to hit my head
against. And no, I wont beg for documentation ;)
From: Ken Tilton
Subject: Re: format line wrap?
Date: 
Message-ID: <A1HDi.994$DR3.189@newsfe12.lga>
Daniel Leidisch wrote:
> Ken Tilton <···········@optonline.net> writes:
> 
> 
>>>That's better:
>>>
>>>(format t "~{~<~%~,40:;~A~>~}"
>>>                 (loop for x across
>>>                      *a-string*
>>>                      collect x))
>>
>>How about some sample output? (hint)
> 
> 
> Hm, I think I'm a little lost...
> 
> CL-USER> (defparameter *a-string* (make-string 100 :initial-element #\x))
> *A-STRING*
> CL-USER> (format t "~{~<~%~,10:;~A~>~}"
>                  (loop for x across
>                       *a-string*
>                       collect x))
> 
> xxxxxxxxxx
> xxxxxxxxxx
> xxxxxxxxxx
> xxxxxxxxxx
> xxxxxxxxxx
> xxxxxxxxxx
> xxxxxxxxxx
> xxxxxxxxxx
> xxxxxxxxxx
> xxxxxxxxxx
> NIL
> 
> CL-USER> (setq *a-string* "The quick brown fox jumps over the lazy dog.")
> "The quick brown fox jumps over the lazy dog."
> CL-USER> (format t "~{~<~%~,5:;~A~>~}"
>                  (loop for x across
>                       *a-string*
>                       collect x))
> 
> The q
> uick 
> brown
>  fox 
> jumps
>  over
>  the 
> lazy 
> dog.
> NIL
> 
> What is wrong? Maybe it's something *really* stupid again, but I don't
> get it. Is it because it returns nil? That would not be a problem,
> would it?

No, of course not, we are really programming here, not pissing around at 
the REPL. So what is wrong? Did you see my version?

> (let ((*print-right-margin* 30)
>       (words (split-sequence #\space
>                (delete #\newline
>                  "Four score and seven years ago our fathers brought
> forth on this continent a new nation conceived in liberty and
> dedicated to the proposition that most people like sports bars."))))
>  (format t "~2%~2T~{~<~%~2T~10:;~:a~>~^ ~}~3%" words))
> 
> ->
>   Four score and
>   seven years ago
>   our fathers
>   brought forth on
>   this continent a
>   new nation
>   conceived in
>   liberty and
>   dedicated to the
>   proposition that
>   most people like
>   sports bars.

You tell me, what is right?


> 
> CL-USER> (defparameter *string*
>            (make-array 0 
>                        :element-type 'character
>                        :fill-pointer 0
>                        :adjustable t))
> *STRING*
> CL-USER> (defparameter *wrapped-string*
>            (make-array 0 
>                        :element-type 'character
>                        :fill-pointer 0
>                        :adjustable t))
> *WRAPPED-STRING*
> CL-USER> (with-output-to-string (string *wrapped-string*)
>            (format string "~{~<~%~,5:;~A~>~}"
>                    (loop for x across
>                         *a-string*
>                         collect x))
>            *wrapped-string*)
> "The q
> uick
>  bro
> wn f
> ox j
> umps
>  ove
> r th
> e la
> zy d
> og."
> 
> I see, it's not very elegant, but doesn't it do what it's supposed
> to? 

Well, let me ask you this: in what real application besides Microsoft 
Scrimshaw would your result be acceptable output?

I am sorry to interrupt the utter detachment from reality of this NG, 
but when His Kennyness asks a question he is trying to get this NG to 
work for his client for free on <gasp> real applications.

Tell you what, you never know when they'll be hiring, I'll pass your 
craftsmanship along and let them know you are available.

> Well, I didn't test all possible cases, and I'm already pretty
> tired... I guess you'll have to show yet another humble dilettante
> the path to enlightenment. ;)

I was thinking "to the door". <sigh>

> p.s.
> 
> I recently checked out cells in order to have something to hit my head
> against. And no, I wont beg for documentation ;)

Go ahead, I'll send you the qualifying exam based on the existing 
documentation. You have to attach screenshots from a successful build of 
Cells-Gtk, Celtk, or Cello when you submit your answers. Hint.

kt

-- 
http://www.theoryyalgebra.com/

"We are what we pretend to be." -Kurt Vonnegut
From: Daniel Leidisch
Subject: Re: format line wrap?
Date: 
Message-ID: <87fy1swt9w.fsf@zeus.home>
Ken Tilton <···········@optonline.net> writes:

> Well, let me ask you this: in what real application besides Microsoft
> Scrimshaw would your result be acceptable output?
>
> I am sorry to interrupt the utter detachment from reality of this NG,
> but when His Kennyness asks a question he is trying to get this NG to
> work for his client for free on <gasp> real applications.
> Tell you what, you never know when they'll be hiring, I'll pass your
> craftsmanship along and let them know you are available.

That's what you wanted:

|I am stuck on one of my homework problems, viz. using format to wrap a
|long string into a block of lines at, say, 40 columns. My instructor
|does not read c.l.l, so can someone help me?

My code does: Take a long string and wrap it into a block of lines.
Period. I care as much about your client as you do care about my feeble
hobby lisp programming. I took the opportunity to learn something
about format (namely ~<), that's it.

For the record:

CL-USER> (format t "~{~<~%~,40:;~A~> ~}"
                 (loop for x in
                      (split-sequence #\space *a-string*)
                      collect x))
Lorem ipsum dolor sit amet, consectetur 
adipisici elit, sed eiusmod tempor 
incidunt ut labore et dolore magna 
aliqua. Ut enim ad minim veniam, quis 
nostrud exercitation ullamco laboris 
nisi ut aliquid ex ea commodi consequat. 
Quis aute iure reprehenderit in 
voluptate velit esse cillum dolore eu 
fugiat nulla pariatur. 
NIL

Doesn't handle newlines and margins, but *none* of those requirements
were formulated in your question.

I just thought that this was another “newbie quitz”, that' why I
posted.

Regards,

dhl
From: Ken Tilton
Subject: Re: format line wrap?
Date: 
Message-ID: <klIDi.440$vN5.394@newsfe12.lga>
Daniel Leidisch wrote:
> Ken Tilton <···········@optonline.net> writes:
> 
> 
>>Well, let me ask you this: in what real application besides Microsoft
>>Scrimshaw would your result be acceptable output?
>>
>>I am sorry to interrupt the utter detachment from reality of this NG,
>>but when His Kennyness asks a question he is trying to get this NG to
>>work for his client for free on <gasp> real applications.
>>Tell you what, you never know when they'll be hiring, I'll pass your
>>craftsmanship along and let them know you are available.
> 
> 
> That's what you wanted:
> 
> |I am stuck on one of my homework problems, viz. using format to wrap a
> |long string into a block of lines at, say, 40 columns. My instructor
> |does not read c.l.l, so can someone help me?
> 
> My code does: Take a long string and wrap it into a block of lines.
> Period. I care as much about...

You Americans are all alike, trying to get away with the bare minimum, 
turning in bad work and then saying "you never said it should not burst 
into flames after a day". Go ahead, like every empire before yours piss 
it all way in smug complacency, never going the extra yard let alone the 
extra mile, never building in a margin for error, never testing the edge 
cases. Just get through the day and the code walkthroughs by the walking 
dead in the cubicles around you, you scratched their asses for them, 
they'll scratch yours. When I was your age I walked five miles through 
the driving snow to get to an unheated schoolhou... hang on, that's a 
different rant. Where was I?

kt

-- 
http://www.theoryyalgebra.com/

"We are what we pretend to be." -Kurt Vonnegut
From: Daniel Leidisch
Subject: Re: format line wrap?
Date: 
Message-ID: <87bqcgwpy9.fsf@zeus.home>
Ken Tilton <···········@optonline.net> writes:

> You Americans are all alike, trying to get away with the bare minimum,
> turning in bad work and then saying "you never said it should not
> burst into flames after a day". Go ahead, like every empire before
> yours piss it all way in smug complacency, never going the extra yard
> let alone the extra mile, never building in a margin for error, never
> testing the edge cases. Just get through the day and the code
> walkthroughs by the walking dead in the cubicles around you, you
> scratched their asses for them, they'll scratch yours. When I was your
> age I walked five miles through the driving snow to get to an unheated
> schoolhou... hang on, that's a different rant. Where was I?

Got it. The next time you'll ask for a line-wrapper, I'll write you a
frickin' text editor. :)

Have fun,

dhl
From: Rob Warnock
Subject: Re: format line wrap?
Date: 
Message-ID: <F-udnZ3s2r7vWELbnZ2dnUVZ_jydnZ2d@speakeasy.net>
Ken Tilton  <·········@gmail.com> wrote:
+---------------
| > I see, it's not very elegant, but doesn't it do what it's supposed to? 
| 
| Well, let me ask you this: in what real application besides Microsoft 
| Scrimshaw would your result be acceptable output?
| 
| I am sorry to interrupt the utter detachment from reality of this NG, 
| but when His Kennyness asks a question he is trying to get this NG to 
| work for his client for free on <gasp> real applications.
+---------------

O.k., here's a partial repost from what I wrote two weeks ago.
First a utility function from my standard personal toolbox:

  (defun \0x (stream arg colon-p at-sign-p &optional mincol padchar)
    "Hexadecimal numeric printing for use with the FORMAT ~/.../ directive.
    Outputs ARG to STREAM as \"~(0x~mincol,padX~)\" [default \"~(0x~8,'0X~)\"].
    If COLON-P, the entire output will be capitalized instead of lowercased.
    If AT-SIGN-P is true, the \"0x\" prefix will be suppressed."
    (let* ((fmt1 "~~~:[···@~](~:[0x~;~]~~~:[8~;~:*~a~],'~:[0~;~:*~a~]x~~)")
           (fmt2 (format nil fmt1 colon-p at-sign-p mincol padchar)))
      (format stream fmt2 arg)))

Then a use of that -- and the "~1,68:;" variant in "~<" -- that I
actually got paid for [not *this* code exactly, but something very,
very close]:

    I use it a lot when building data initialization tables in C code:

    > (let ((data (loop for i below 24 nconc (list (random 0x100000000)
                                                   (random 256))))
            (instance "georgey"))
        (format t "~%foo_t ~a_foos[~d] = {~
              ~%~{~<~%~1,68:;  {~/0x/, ~2/0x/}~>~^,~}~%};~%"
              instance (/ (length data) 2) data))

    foo_t georgey_foos[24] = {
      {0x21a41a5c, 0x87},  {0x1c63b86e, 0xb4},  {0x894c25d5, 0xa1},
      {0x9979b7fe, 0xbb},  {0xc2ad44aa, 0x4d},  {0xe2826239, 0x70},
      {0x053b537e, 0x05},  {0x6ac226e8, 0xbe},  {0x1252ea73, 0x20},
      {0xe3001d4a, 0x12},  {0x9a006313, 0x31},  {0x299d2f64, 0x54},
      {0x90feb745, 0xda},  {0xc7ed257b, 0xc1},  {0xa6e8e18a, 0x51},
      {0x0fdb8569, 0xed},  {0x713c27e0, 0xa8},  {0xd975dbac, 0x2d},
      {0xb4263772, 0x85},  {0xe6cdaaa9, 0x48},  {0x7db24d29, 0xf8},
      {0x87e5aa36, 0xa3},  {0xb56e3dd7, 0xe2},  {0x3cf23443, 0x4e}
    };
    NIL
    > 

Wrap the whole thing in (WITH-OPEN-FILE (S "xyz.c" :DIRECTION OUTPUT) ...)
and replace the (FORMAT T ...) with (FORMAT S ...) and now you're
writing nicely-formatted C code the easy way.  ;-}

[Note: The real code -- using data parsed from a flat-file
configuration database, not randomness as above -- built several
tables of "foo_t" and then an index table on top of all that...]


-Rob

p.s. And, no, I wasn't being paid to code Lisp per se; I was
being paid to get a piece of work done [a Linux kernel driver,
if you must know], and using Lisp to do parts of it was just
the fastest, simplest, least error-prone way I knew.  ;-}  ;-}

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Damien Kick
Subject: Re: format line wrap?
Date: 
Message-ID: <13fjqa5l2k9kc86@corp.supernews.com>
Rob Warnock wrote:

> O.k., here's a partial repost from what I wrote two weeks ago.
> First a utility function from my standard personal toolbox:
> 
>   (defun \0x (stream arg colon-p at-sign-p &optional mincol padchar)
>     "Hexadecimal numeric printing for use with the FORMAT ~/.../ directive.
>     Outputs ARG to STREAM as \"~(0x~mincol,padX~)\" [default \"~(0x~8,'0X~)\"].
>     If COLON-P, the entire output will be capitalized instead of lowercased.
>     If AT-SIGN-P is true, the \"0x\" prefix will be suppressed."
>     (let* ((fmt1 "~~~:[···@~](~:[0x~;~]~~~:[8~;~:*~a~],'~:[0~;~:*~a~]x~~)")
>            (fmt2 (format nil fmt1 colon-p at-sign-p mincol padchar)))
>       (format stream fmt2 arg)))

I'm not sure if this feeling I'm feeling is awe, fear, or nausea.
From: Rob Warnock
Subject: Re: format line wrap?
Date: 
Message-ID: <x7adnerjG_n5i2fbnZ2dnUVZ_hWdnZ2d@speakeasy.net>
Damien Kick  <·····@earthlink.net> wrote:
+---------------
| Rob Warnock wrote:
| > O.k., here's a partial repost from what I wrote two weeks ago.
| > First a utility function from my standard personal toolbox:
| > 
| >   (defun \0x (stream arg colon-p at-sign-p &optional mincol padchar)
| >     "Hexadecimal numeric printing for use with the FORMAT ~/.../ directive.
| >     Outputs ARG to STREAM as \"~(0x~mincol,padX~)\" [default
| \"~(0x~8,'0X~)\"].
| >     If COLON-P, the entire output will be capitalized instead of lowercased.
| >     If AT-SIGN-P is true, the \"0x\" prefix will be suppressed."
| >     (let* ((fmt1 "~~~:[···@~](~:[0x~;~]~~~:[8~;~:*~a~],'~:[0~;~:*~a~]x~~)")
| >            (fmt2 (format nil fmt1 colon-p at-sign-p mincol padchar)))
| >       (format stream fmt2 arg)))
| 
| I'm not sure if this feeling I'm feeling is awe, fear, or nausea.
+---------------

Come on, CL isn't Scheme, you know!! Neither fear nor nausea is called
for. I do lots of hardware debugging and need to be able to show co-workers
dumps they can read... and none of them read Lisp but thay *all* read C.
Hence a "0" readmacro [so #x123 can be typed in as 0x123] and a "~/0x/"
FORMAT function so when I'm peeking & poking hardware things look like
a C or Tcl programmer expects them to... mostly:

    $ opfr
    opfr> deflex foo "abcde"

    FOO
    opfr> d32 foo
    0x48039998: 0x0000002a 0x00000014 0x64636261 0x00000065
    0x480399a8: 0x4803999f 0x28f0000b 0x4803999f 0x48039993
    0x480399b8: 0x4803999f 0x28f0000b 0x4803996f 0x480399bb
    0x480399c8: 0x48bb1f97 0x480399c3 0x480399cb 0x480399db
    opfr> 

Which, being decoded, is:

                        +-- CMUCL's heap type tag for SIMPLE-BASE-STRING
		        |          +-- (LENGTH "abcde") as a FIXNUM
		        |          |   [Hint: What is (ASH #x14 -2)?
		        |          |    ___ The string ___
		        |          |   /  [Little-Endian] \
    0x48039998: 0x0000002a 0x00000014 0x64636261 0x00000065

Now let's get *really* nasty!!  ;-}  ;-}

    opfr> code-char (r8 (+ 0x48039998 10))

    #\c
    opfr> w8 (+ 0x48039998 10) (char-code #\C) (char-code #\D)

    hwtool> foo

    "abCDe"
    opfr> 


-Rob

[1] OPFR == "Outer-Parenthesis-Free REPL", a trivial wrapper
    around a CL REPL that gives it a Tcl-like flavor as long
    as you're only typing pre-defined functions, variables,
    and literals. And, yes, once you have any sub-expressions
    the underlying Lisp shows through. Turns out not to be a
    biggy, as long as the top-level is paren-free. [I have written
    of the phenomenon at length previously. Google is your friend.]

[2] Yes, I know I'm illegally modifying a literal. It's just a
    quick example. But if you like, replace the first line with:

	deflex foo (copy-seq "abcde")

[3] Here's the D32 function [slightly trimmed]:

      (defun d32 (addr &optional (len #x40) (print-addr addr))
	...[a bunch of error-checking & argument coercion elided,
	    following which ADDR is now an 8-byte-aligned memory address]...
	(loop for i from 0 by 16 below len do
	 (format t "~2/0x/:" (+ print-addr i))
	 (loop for j from i by 4 below (min len (+ i 16)) do
	   (format t " ~/0x/" (r32 (+ addr j))))
	 (format t "~%"))
	 (values)) ; suppress ugly "NIL"

    Yes, the "~2/0x/" could be written as "~(0x~2,'0x~)" and the
    "~/0x/" as ~(0x~8,'0x~)", but I type a lot of one-off hex-output
    FORMATs at the REPL, too, and "~/0x/" is just easier.

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Daniel Leidisch
Subject: Re: format line wrap?
Date: 
Message-ID: <87myw0wwmn.fsf@zeus.home>
Daniel Leidisch <····@leidisch.net> writes:

> CL-USER> (with-output-to-string (string *wrapped-string*)

Guess I should have named “string” “stream” and there is no need for a
special, but I'll just take a nap now.

dhl