From: Peter Seibel
Subject: Is there a null-output-stream?
Date: 
Message-ID: <m3wuml48ti.fsf@localhost.localdomain>
Or a way to make one? By null-output-stream I mean an object I can use
were code expects an output-stream but which sends it's output to the
big bit-bucket in the sky. More generally, is there a way to make my
own kind of subclass of stream? My simple-minded experiment looked
like this:

    [1] CL-USER(8660): (defclass my-stream (stream) ())
    #<STANDARD-CLASS MY-STREAM>
    [1] CL-USER(8661): (format (make-instance 'my-stream) "foo")
    Error: First arg to format not t, nil, a stream, or a string with fill
           pointer: #<MY-STREAM @ #x7189b52a>
      [condition type: SIMPLE-ERROR]

    Restart actions (select using :continue):
     0: Return to Debug Level 1 (an "abort" restart).
     1: Return to Top Level (an "abort" restart).
     2: Abort entirely from this process.
    [2] CL-USER(8666): 

I'm not really sure what I expected to happen, but saying that
(make-instance 'my-stream) isn't a stream, doesn't give me a lot of
hope that I was heading down the right path.

-Peter

-- 
Peter Seibel
·····@javamonkey.com

From: JP Massar
Subject: Re: Is there a null-output-stream?
Date: 
Message-ID: <3df2bd86.197136793@netnews.attbi.com>
On Sun, 08 Dec 2002 01:09:50 GMT, Peter Seibel <·····@javamonkey.com>
wrote:

>Or a way to make one? 

(setq *dev-null* (make-broadcast-stream))

 "A broadcast stream is an output stream which has associated with it
a set of zero or more output streams such that any output sent to the
broadcast stream gets passed on as output to each of the associated
output streams. (If a broadcast stream has no component streams, then
all output to the broadcast stream is discarded.)"

http://www.lispworks.com/reference/HyperSpec/Body/t_broadc.htm#broadcast-stream
From: Paolo Amoroso
Subject: Re: Is there a null-output-stream?
Date: 
Message-ID: <qELzPVNLXSkKC2O1c8WEApg+EA+C@4ax.com>
On Sun, 08 Dec 2002 01:09:50 GMT, Peter Seibel <·····@javamonkey.com>
wrote:

> Or a way to make one? By null-output-stream I mean an object I can use
> were code expects an output-stream but which sends it's output to the
> big bit-bucket in the sky. More generally, is there a way to make my

From the comp.lang.lisp FAQ:


Subject: [2-16]  How can I create a stream that acts like UNIX's /dev/null
                 (i.e., gobbles any output and immediately signals EOF on
                 input operations)?

(defparameter *dev-null*
  #-lispm
  (make-two-way-stream (make-concatenated-stream) (make-broadcast-stream))
  ;; Since Lisp Machines have a built-in /dev/null which handles
  ;; additional, non-standard operations, we'll use that instead.
  #+lispm #'system:null-stream)


That FAQ is unmaintained, but it still provides a lot of useful
information. Have (de)fun,


Paolo
-- 
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://www.paoloamoroso.it/ency/README
From: Peter Seibel
Subject: Re: Is there a null-output-stream?
Date: 
Message-ID: <m3of7v4w0b.fsf@localhost.localdomain>
Paolo Amoroso <·······@mclink.it> writes:

> On Sun, 08 Dec 2002 01:09:50 GMT, Peter Seibel
> <·····@javamonkey.com> wrote:
> 
> > Or a way to make one? By null-output-stream I mean an object I can
> > use were code expects an output-stream but which sends it's output
> > to the big bit-bucket in the sky. More generally, is there a way
> > to make my
> 
> From the comp.lang.lisp FAQ:

Doh! I'm so ashamed. Thanks.

-Peter

-- 
Peter Seibel
·····@javamonkey.com
From: Duane Rettig
Subject: Re: Is there a null-output-stream?
Date: 
Message-ID: <4ptsb6sd5.fsf@beta.franz.com>
Peter Seibel <·····@javamonkey.com> writes:

> Or a way to make one? By null-output-stream I mean an object I can use
> were code expects an output-stream but which sends it's output to the
> big bit-bucket in the sky. More generally, is there a way to make my
> own kind of subclass of stream? My simple-minded experiment looked
> like this:
> 
>     [1] CL-USER(8660): (defclass my-stream (stream) ())
>     #<STANDARD-CLASS MY-STREAM>
>     [1] CL-USER(8661): (format (make-instance 'my-stream) "foo")
>     Error: First arg to format not t, nil, a stream, or a string with fill
>            pointer: #<MY-STREAM @ #x7189b52a>
>       [condition type: SIMPLE-ERROR]
> 
>     Restart actions (select using :continue):
>      0: Return to Debug Level 1 (an "abort" restart).
>      1: Return to Top Level (an "abort" restart).
>      2: Abort entirely from this process.
>     [2] CL-USER(8666): 
> 
> I'm not really sure what I expected to happen, but saying that
> (make-instance 'my-stream) isn't a stream, doesn't give me a lot of
> hope that I was heading down the right path.

Simple-streams (as implemented in Allegro CL and for CMUCL by Paul Foley:
http://users.actrix.gen.nz/mycroft/simple-stream.tar.gz) provides a
null-simple-stream which does what you want, although it is not output-only:

CL-USER(1): (setq bb (make-instance 'null-simple-stream))
#<NULL-SIMPLE-STREAM @ #x7161399a>
CL-USER(2): (format bb "This goes nowhere~%")
NIL
CL-USER(3): (read-char bb)
Error: eof encountered on stream #<NULL-SIMPLE-STREAM @ #x7161399a>
  [condition type: END-OF-FILE]

Restart actions (select using :continue):
 0: Return to Top Level (an "abort" restart).
 1: Abort entirely from this process.
[1] CL-USER(4): 

-- 
Duane Rettig    ·····@franz.com    Franz Inc.  http://www.franz.com/
555 12th St., Suite 1450               http://www.555citycenter.com/
Oakland, Ca. 94607        Phone: (510) 452-2000; Fax: (510) 452-0182