Subject: Re: sending output from display to a file
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1999/10/05
Newsgroups: comp.lang.scheme
Message-ID: <7tcit9$dve3o@fido.engr.sgi.com>
<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)
	      (newline)))
	> (with-output-to-file "foo.bar" top)
	> ^D
	% cat foo.bar
	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

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