This already exists. It is called "open-output-nowhere" Jay
On Mon, May 24, 2010 at 4:48 PM, <stamo...@racket-lang.org> wrote: > stamourv has updated `master' from 3b90cdb872 to 9c12b7d2e7. > http://git.racket-lang.org/plt/3b90cdb872..9c12b7d2e7 > > =====[ 1 Commits ]====================================================== > > 9c12b7d Vincent St-Amour <stamo...@racket-lang.org> 2010-05-24 18:32 > : > | Added a /dev/null-like output port to unstable. > : > M collects/meta/props | 3 +++ > A collects/tests/unstable/port.rkt > A collects/unstable/port.rkt > A collects/unstable/scribblings/port.scrbl > M collects/unstable/scribblings/unstable.scrbl | 1 + > > =====[ Overall Diff ]=================================================== > > collects/meta/props > ~~~~~~~~~~~~~~~~~~~ > --- OLD/collects/meta/props > +++ NEW/collects/meta/props > @@ -1802,6 +1802,7 @@ path/s is either such a string or a list of them. > "collects/tests/units/test-unit.rktl" drdr:command-line (racket "-f" *) > "collects/tests/unstable/byte-counting-port.rkt" responsible (jay) > "collects/tests/unstable/generics.rkt" responsible (jay) > +"collects/tests/unstable/port.rkt" responsible (stamourv) > "collects/tests/unstable/srcloc.rktl" responsible (cce) drdr:command-line > (racket "-f" *) > "collects/tests/utils" responsible (unknown) > "collects/tests/utils/gui.rkt" drdr:command-line (gracket-text "-t" *) > @@ -1848,12 +1849,14 @@ path/s is either such a string or a list of them. > "collects/unstable/match.rkt" responsible (samth) > "collects/unstable/mutated-vars.rkt" responsible (samth) > "collects/unstable/poly-c.rkt" responsible (samth) > +"collects/unstable/port.rkt" responsible (stamourv) > "collects/unstable/scribblings/byte-counting-port.scrbl" responsible (jay) > "collects/unstable/scribblings/debug.scrbl" responsible (samth) > "collects/unstable/scribblings/hash.scrbl" responsible (samth) > "collects/unstable/scribblings/match.scrbl" responsible (samth) > "collects/unstable/scribblings/mutated-vars.scrbl" responsible (samth) > "collects/unstable/scribblings/poly-c.scrbl" responsible (samth) > +"collects/unstable/scribblings/port.scrbl" responsible (stamourv) > "collects/unstable/scribblings/sequence.scrbl" responsible (samth) > "collects/unstable/scribblings/utils.rkt" responsible (samth) > "collects/unstable/sequence.rkt" responsible (samth) > > collects/tests/unstable/port.rkt > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > --- /dev/null > +++ NEW/collects/tests/unstable/port.rkt > @@ -0,0 +1,23 @@ > +#lang racket > + > +(require unstable/port > + test-engine/scheme-tests) > + > +(check-expect (port? null-output-port) > + #t) > + > +(check-expect (with-output-to-string > + (lambda () > + (parameterize ([current-output-port null-output-port]) > + (display "can't see me")))) > + "") > + > +(check-expect (with-output-to-string > + (lambda () > + (display "now you see me") > + (parameterize ([current-output-port null-output-port]) > + (display "now you don't")) > + (display "you can see me again"))) > + "now you see meyou can see me again") > + > +(test) > > collects/unstable/port.rkt > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > --- /dev/null > +++ NEW/collects/unstable/port.rkt > @@ -0,0 +1,18 @@ > +#lang racket/base > + > +(provide null-output-port) > + > +;; taken from section 12.1.9 of the reference > +;; -- stamourv > +(define null-output-port > + (make-output-port > + 'null > + always-evt > + (lambda (s start end non-block? breakable?) (- end start)) > + void > + (lambda (special non-block? breakable?) #t) > + (lambda (s start end) (wrap-evt > + always-evt > + (lambda (x) > + (- end start)))) > + (lambda (special) always-evt))) > > collects/unstable/scribblings/port.scrbl > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > --- /dev/null > +++ NEW/collects/unstable/scribblings/port.scrbl > @@ -0,0 +1,16 @@ > +#lang scribble/doc > +@(require scribble/base > + scribble/manual > + "utils.rkt" > + (for-label unstable/port > + racket/base)) > + > +...@title[#:tag "port"]{Port} > + > +...@defmodule[unstable/port] > + > +...@unstable[@author+email["Vincent St-Amour" "stamo...@ccs.neu.edu"]] > + > +...@defthing[null-output-port output-port?]{ > + Output port that discards everything written to it. > +} > > collects/unstable/scribblings/unstable.scrbl > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > --- OLD/collects/unstable/scribblings/unstable.scrbl > +++ NEW/collects/unstable/scribblings/unstable.scrbl > @@ -90,6 +90,7 @@ Keep documentation and tests up to date. > �...@include-section["sequence.scrbl"] > �...@include-section["hash.scrbl"] > �...@include-section["match.scrbl"] > +...@include-section["port.scrbl"] > �...@include-section["skip-list.scrbl"] > �...@include-section["interval-map.scrbl"] > �...@include-section["generics.scrbl"] > -- Jay McCarthy <j...@cs.byu.edu> Assistant Professor / Brigham Young University http://teammccarthy.org/jay "The glory of God is Intelligence" - D&C 93 _________________________________________________ For list-related administrative tasks: http://list.cs.brown.edu/mailman/listinfo/plt-dev