From: Marco Antoniotti
Subject: The problem of the day.  Inserting a #\Newline every X characters.
Date: 
Message-ID: <lwzorokb8u.fsf@parades.rm.cnr.it>
Hi,

I am pretty lazy today and I have the following problem.

I wrote a bunch of routines that have the following signature

	(defun routine-x (some-arg &optional (stream *standard-output*)))

I have many of them and all pass around the (CHARACTER) STREAM arg and
write to it.

Now I have the following problem. I want the the stream to be broken
up into X character wide rows by insertinf #\Newline's.

However.  The operation must be done online, and the original routines
should be left alone.

What would be a good way to achieve this goal (if possible) using
streams, pretty printing and other magical tools from the COMMON-LISP
package?

Thanks in advance.

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa

From: Tom Breton
Subject: Re: The problem of the day.  Inserting a #\Newline every X characters.
Date: 
Message-ID: <m3d7oknqd2.fsf@world.std.com>
Marco Antoniotti <·······@parades.rm.cnr.it> writes:

> Hi,
> 
> I am pretty lazy today and I have the following problem.
> 
> I wrote a bunch of routines that have the following signature
> 
> 	(defun routine-x (some-arg &optional (stream *standard-output*)))
> 
> I have many of them and all pass around the (CHARACTER) STREAM arg and
> write to it.
> 
> Now I have the following problem. I want the the stream to be broken
> up into X character wide rows by insertinf #\Newline's.
> 
> However.  The operation must be done online, and the original routines
> should be left alone.
> 
> What would be a good way to achieve this goal (if possible) using
> streams, pretty printing and other magical tools from the COMMON-LISP
> package?

In such cases it makes sense to ask what you really want to
accomplish.  But I'm sure you know that, and you prolly already thaut
it thru, so let's just jump in:

I'd do the entire operation in post-processing.  I'd use
with-output-to-string or similar, and then loop over the result
string, collecting N-character-long piece, newline, piece, newline,
etc.

-- 
Tom Breton, http://world.std.com/~tob
Not using "gh" since 1997. http://world.std.com/~tob/ugh-free.html
Rethink some Lisp features, http://world.std.com/~tob/rethink-lisp/index.html
From: Rob Warnock
Subject: Re: The problem of the day.  Inserting a #\Newline every X characters.
Date: 
Message-ID: <8bfcea$nv5sm$1@fido.engr.sgi.com>
Marco Antoniotti  <·······@parades.rm.cnr.it> wrote:
+---------------
| Now I have the following problem. I want the the stream to be broken
| up into X character wide rows by insertinf #\Newline's.
| 
| However.  The operation must be done online, and the original routines
| should be left alone.
| 
| What would be a good way to achieve this goal (if possible) using streams,
| pretty printing and other magical tools from the COMMON-LISP package?
+---------------

Gray Streams, maybe?


-Rob

-----
Rob Warnock, 41L-955		····@sgi.com
Applied Networking		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		PP-ASEL-IA
Mountain View, CA  94043
From: Marco Antoniotti
Subject: Re: The problem of the day.  Inserting a #\Newline every X characters.
Date: 
Message-ID: <lwog7zmmoa.fsf@parades.rm.cnr.it>
Hello there...

did I ask for something way too complex?

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa
From: Pierre R. Mai
Subject: Re: The problem of the day.  Inserting a #\Newline every X characters.
Date: 
Message-ID: <87em8vxrr5.fsf@orion.dent.isdn.cs.tu-berlin.de>
Marco Antoniotti <·······@parades.rm.cnr.it> writes:

> Hello there...
> 
> did I ask for something way too complex?

No, but the solutions mentioned (either use gray-streams, or roll your 
own via string-streams) seem to be the only clean solutions to your
problem.  For related problems take a look at how most implementations
(including CMUCL) implement indenting-streams, needed for
pretty-printing.  Either you handle this at the stream level, or
things get ugly, quickly, IMHO...

Regs, Pierre.

-- 
Pierre Mai <····@acm.org>         PGP and GPG keys at your nearest Keyserver
  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]