[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

call-with-xput-port vs. call-with-xput-file



I favor changing call-with-input-file and call-with-output-file to
call-with-input-port and call-with-output-port.  However, I have some
questions related to the change and to ports in general.

1.  I saw lots of confusion over the fact that you open a file (with
open-input-file and open-output-file) but close a port (with close-
input-port and close-output-port).  Changing the "call-with" names
could increase the confusion.  Should we change open-input-file and
open-output-file to open-input-port and open-output-port?

2.  I have added string ports to Chez Scheme and need to choose names.
If we have call-with-...-file and open-...-file, I can introduce the
names call-with-...-string and open-...-string.  On the other hand,
if we have call-with-...-port and open-...-port, I can introduce the
names call-with-...-string-port and open-...-string-port.  The names
are longer but perhaps more descriptive.  How do these names sound?
The point of this question is that any names we choose should
generalize to other types of ports.

3.  Currently, there is no way to change the current ports to anything
other than a freshly-opened file (as with the inessential with-input-
from-file and with-output-to-file).  Stylistically, I think it is
better to never change the standard ports.  But if they can be changed,
I'd like to have a way for a debugger, say, to change them back to an
existing file (usually the original current ports), so that anything
the user executes goes to the expected place.  Without this we cannot
hope to write a reliable portable debugger (and debug code with calls
to with-input-from-file or with-output-to-file).

4.  Also, there is no way to change the current ports permanantly.
That is, it is not possible to write (set-current-input! <port>) or
(set-current-output! <port>).  Again, I don't think this is good
practice, but some might rue the inability to do so.

5.  Why is call-with-input-file essential and open-input-file not?
If call-with-input-file is analogous to call-with-current-continuation,
why do we not have (call-with-new-string <length> <proc>) instead of
make-string or (call-with-pair <obj1> <obj2> <proc>) instead of cons,
etc?  Because call-with-current-continuation is special---a function
make-continuation would be problematic.  In short, while I see the
merit in with-input-from-file since it closes the file and rebinds a
standard port, I cannot see the merit in call-with-input-file.  Can
we flush call-with-input-file and call-with-output-file and promote
open-input-file and open-output-file to essential status?