From: Vladimir Zolotykh
Subject: 'data sink' stream
Date: 
Message-ID: <3C443C6A.5E3EB1E0@eurocom.od.ua>
I think it should be simple, but for now I can't catch that: 'How to
implement "data sink"' (e.g something like /dev/null) ?

What I might need it for ? Well, for example a have I function that
performs several calculations and tests. If all tests passes it prints
some informational message and returns T. If not it prints some
warning message and returns NIL. At some time I found that it will be
convenient to call it in a "probe mode" in which it just returns (T or
NIL for example) but prints nothing. Having 'data sink' I could simply
passed it as argument, w/o it I should rewrite code with
conditionals. That, in its turn deems the 'main tast' of the function.

-- 
Vladimir Zolotykh                         ······@eurocom.od.ua

From: Duane Rettig
Subject: Re: 'data sink' stream
Date: 
Message-ID: <4wuyjr1gy.fsf@beta.franz.com>
Vladimir Zolotykh <······@eurocom.od.ua> writes:

> I think it should be simple, but for now I can't catch that: 'How to
> implement "data sink"' (e.g something like /dev/null) ?
> 
> What I might need it for ? Well, for example a have I function that
> performs several calculations and tests. If all tests passes it prints
> some informational message and returns T. If not it prints some
> warning message and returns NIL. At some time I found that it will be
> convenient to call it in a "probe mode" in which it just returns (T or
> NIL for example) but prints nothing. Having 'data sink' I could simply
> passed it as argument, w/o it I should rewrite code with
> conditionals. That, in its turn deems the 'main tast' of the function.

Others have posted the broadcast-stream solution (although that can
only work in the output direction).  In Allegro CL you can also use
gray streams using the undocumented null-stream class:

CL-USER(1): (make-instance 'excl::null-stream)
#<EXCL::NULL-STREAM @ #x7150f1d2>
CL-USER(2): (pprint (mop:class-precedence-list (class-of *)))

(#<STANDARD-CLASS EXCL::NULL-STREAM>
 #<STANDARD-CLASS FUNDAMENTAL-CHARACTER-INPUT-STREAM>
 #<STANDARD-CLASS FUNDAMENTAL-CHARACTER-OUTPUT-STREAM>
 #<STANDARD-CLASS FUNDAMENTAL-CHARACTER-STREAM>
 #<STANDARD-CLASS FUNDAMENTAL-BINARY-INPUT-STREAM>
 #<STANDARD-CLASS FUNDAMENTAL-INPUT-STREAM>
 #<STANDARD-CLASS FUNDAMENTAL-BINARY-OUTPUT-STREAM>
 #<STANDARD-CLASS FUNDAMENTAL-OUTPUT-STREAM>
 #<STANDARD-CLASS FUNDAMENTAL-BINARY-STREAM>
 #<STANDARD-CLASS FUNDAMENTAL-STREAM> #<STANDARD-CLASS STREAM>
 #<STANDARD-CLASS STANDARD-OBJECT> #<BUILT-IN-CLASS T>)
CL-USER(3): 

or you can use the new simple-streams null-simple-stream class:

CL-USER(3): (make-instance 'null-simple-stream)
#<NULL-SIMPLE-STREAM @ #x7150f622>
CL-USER(4): (pprint (mop:class-precedence-list (class-of *)))

(#<STANDARD-CLASS NULL-SIMPLE-STREAM>
 #<STANDARD-CLASS SINGLE-CHANNEL-SIMPLE-STREAM>
 #<STANDARD-CLASS SIMPLE-STREAM> #<STANDARD-CLASS STREAM>
 #<STANDARD-CLASS STANDARD-OBJECT> #<BUILT-IN-CLASS T>)
CL-USER(5): 

-- 
Duane Rettig          Franz Inc.            http://www.franz.com/ (www)
1995 University Ave Suite 275  Berkeley, CA 94704
Phone: (510) 548-3600; FAX: (510) 548-8253   ·····@Franz.COM (internet)
From: Barry Margolin
Subject: Re: 'data sink' stream
Date: 
Message-ID: <U4Y08.6$j%.25547@burlma1-snr2>
In article <·················@eurocom.od.ua>,
Vladimir Zolotykh  <······@eurocom.od.ua> wrote:
>I think it should be simple, but for now I can't catch that: 'How to
>implement "data sink"' (e.g something like /dev/null) ?

From CLTL2 section 21.2 "Creating New Streams", under
MAKE-BROADCAST-STREAM: "If no <streams> are given as arguments, then the
result is a 'bit sink'; all output to the resulting stream is discarded."

(let ((null-stream (make-broadcast-stream)))
  ...)

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Janis Dzerins
Subject: Re: 'data sink' stream
Date: 
Message-ID: <a21l86$qq$1@milzis.latnet.lv>
Barry Margolin <······@genuity.net> writes:

> In article <·················@eurocom.od.ua>,
> Vladimir Zolotykh  <······@eurocom.od.ua> wrote:
> >I think it should be simple, but for now I can't catch that: 'How to
> >implement "data sink"' (e.g something like /dev/null) ?
> 
> From CLTL2 section 21.2 "Creating New Streams", under
> MAKE-BROADCAST-STREAM: "If no <streams> are given as arguments, then the
> result is a 'bit sink'; all output to the resulting stream is discarded."

Also stated in CLHS in "System Class BROADCAST-STREAM" page.

> (let ((null-stream (make-broadcast-stream)))
>   ...)

And then, bind it to *standard-output* if the output goes there, like:

(let ((*standard-output* (make-broadcast-stream)))
  ...)

-- 
Janis Dzerins

  Eat shit -- billions of flies can't be wrong.