Subject: Re: special filenames in MzScheme (Windows)
From: (Rob Warnock)
Date: 2000/05/18
Newsgroups: comp.lang.scheme
Message-ID: <8g0e2i$c9jc1$>
Boris Schaefer  <> wrote:
| i want to send some data directly to the parallel port, so I tried
| (with-output-to-file "LPT1:" ...), but it doesn't work (at least not
| with NT), and tells me that the file already exists or something.
| i tried petite-chez and it works there, but I'd really like to use
| MrEd and so it would be nice if someone found out how to do this and
| could tell me.

Well, *both* Petite-Chez and MzScheme (the engine MrEd is based on)
are actually in conformance with R5RS, which says [edited heavily]:

	(with-output-to-file string thunk)
	String should be a string naming a file... the
	effect is unspecified if the file already exists. 

And of course, special filenames like "LPT:" under DOS or Windows,
or character devices like "/dev/lp" under Unix/Linux/etc., "already
exist", hence both behaviors are "legal".

However, all is not lost -- MzScheme allows additional optional flag
arguments to the various file-opening procedures to give finer control
of the behavior. See <URL:
mzscheme/node119.htm> for the gory details, but I think the following
example should help:

	> (define foo
	    (lambda ()
	      (display "Hello, World!")
	> (with-output-to-file "/dev/tty" foo)
	with-output-to-file: file "/dev/tty" exists
	> (with-output-to-file "/dev/tty" foo 'append)
	Hello, World!
	> (with-output-to-file "/dev/tty" foo 'truncate)
	Hello, World!

In the case of Unix character devices, the "append" and "truncate"
flags do the same thing, but I'm not sure which flag you'll need
for "LPT1:" on Windows...


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