Subject: Re: sending output from display to a file
From: (Rob Warnock)
Date: 1999/10/05
Newsgroups: comp.lang.scheme
Message-ID: <7tcit9$>
<enoll@CSTP.UMKC.EDU> wrote:
| The top-level modules take no arguments and produce output only via display.
| I would like to be able to execute the top-level code and have the output
| go to a file.  I tried doing, if I remember correctly
|   (with-output-port (my-code) )
| but it complained because | I didn't give it a port.

Unfortunately, "with-output-port" is not a standard Scheme procedure
(though at least one Scheme implementation provides "with-output-to-port")
Try (with-output-to-file "filename" <thunk>) instead, e.g.:

	% hs
	> (define (top)
	    (do ((i 1 (+ i 1)))
		  ((> i 5))
	      (display "this is line ")
	      (display i)
	> (with-output-to-file "" top)
	> ^D
	% cat
	this is line 1
	this is line 2
	this is line 3
	this is line 4
	this is line 5

Or, if you want to mess with ports explicitly, remember that "display",
"write", and "newline" take an optional second argument, a port.


Rob Warnock, 8L-846
Applied Networking
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		FAX: 650-933-0511
Mountain View, CA  94043	PP-ASEL-IA