[plt-scheme] Noticeable absence of (with-output-to-port ...) and(with-input-from-port ...)

From: Jos Koot (jos.koot at telefonica.net)
Date: Thu Sep 11 13:55:17 EDT 2008

The absence of with-output-to-port has no deep foundation. It can easily be 
made by yourself:

(define-syntax with-output-to-port
 (syntax-rules ()
  ((_ port thunk)
   (parameterize ((current-output-port port)) (thunk)))))

Actually the same holds for with-output-to-file, but this one is required by 
RnRS (at least for n>4)
----- Original Message ----- 
From: "Robby Findler" <robby at cs.uchicago.edu>
To: "Ernie Smith" <esmith at acanac.net>
Cc: "PLT Scheme List" <plt-scheme at list.cs.brown.edu>
Sent: Thursday, September 11, 2008 4:18 PM
Subject: Re: [plt-scheme] Noticeable absence of (with-output-to-port ...) 
and(with-input-from-port ...)

> On Thu, Sep 11, 2008 at 8:36 AM, Ernie Smith <esmith at acanac.net> wrote:
>> I was looking to redirect intput and output of existing
>> scheme functions to pipes.
>> In the spirit of  "The art of taking out the weakness that  causes the 
>> need
>> to add features" (forgive the paraphrase, I couldn't find the original
>> quote),
> Its the introduction of the RnRS reports. eg:
> http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-3.html
>> I am
>> surprised to find that  though (with-output-to-file ...) is defined,
>> the more general (with-output-to-port ...)  appears to be lacking. It 
>> would
>> seem to me that  (with-output-to-port ...) would make other
>> (with-output-to-xxx ...) unnecessary, but the the converse is not true,
>> so I surmise there is an underlying implementation problem or a conflict
>> with a more substantial issue. Perhaps someone could edify me on this.
>> Why is it missing?
> With-output-to-port wouldn't do anything. Output already goes to a
> port. The one returned by current-output-port. Input also comes from a
> port; you guessed it: current-input-port.
> You might try reading about those in help desk. Be sure to also read
> about the scheme/port library which has some useful helper functions.
> I suggest starting with the Guide:
> http://docs.plt-scheme.org/guide/i_o.html
> Robby
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.