Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!apple!usc!orion.cf.uci.edu!uci-ics!milne From: milne@ics.uci.edu (Alastair Milne) Newsgroups: comp.lang.pascal Subject: Re: Standard Pascal Message-ID: <19438@paris.ics.uci.edu> Date: 11 Jul 89 20:14:09 GMT References: <8616@pyr.gatech.EDU> <18965@paris.ics.uci.edu> Sender: news@paris.ics.uci.edu Lines: 68 schwartz@shire.cs.psu.edu (Scott Schwartz) writes: >Actually GET and PUT are much better than READ and WRITE. One reason is >that you can interrogate the file variable without committing to read it. >For example, to strip leading whitespace from the input stream, you >do the following: > while (input^ in [space, tab, newline, cr, formfeed]) do > get (input) How does this constitute not commiting to read the file variable? You are doing exactly that when you dereference the file variable to get its window. I don't see how this differs at all from repeat read( input, ch); until not (ch in [space, tab, newline, cr, formfeed]); except that you first copy what would have been the file variable reference into another variable. Saving one variable seems to me a trivial difference in transport. Replacing the references so that all "input^"'s become "ch"'s is worse, but not much. >This works without side effects, so that it can be bundled up in a >black box and called by anyone. I/O almost always has side effects, because there's almost always something that can go wrong. I am not in fact happy with either of the loops above because neither realises the possiblity of I/O error. (BTW, in Turbo, if you fail to clear a non-zero IOResult by calling the function IOResult, all I/O attempts to/from that file will fail until the result is finally cleared.) To the extent, however, that your while loop is free of side effects, and can be called as a module, so is and can the repeat. >Using read and write requires that >the user maintain state information: global variables which get checked >before doing any I/O. Please elaborate: what state information? Maybe I should be seeing what you mean, but I don't. >I would say a lot harder. ....This requres >checking all calls to read and write to make sure they read from your >pushed-back data if it is available. Again, I'm not following: I see no pushed-back data in the loop you gave. The series of get's the while does is exactly equivalent to the series of read(ch)'s in the repeat I added. In fact, if the correct definition of read is used, they must be, because the read is simply "ch := input^; get (input);" Please don't take this as an endorsement of Borland's substitution: I wish they hadn't done it -- it has added to the inconvenience of some transport I've had to do from UCSD, and doubtlessly is doing and will continue to do the same for lots of other projects. As I said before, I think it's very much because they hadn't used a window implementation of file variables, and didn't want to change it, so the associated syntax needed for using GET and PUT wasn't available. >I'd start by typing in the unix stdio style >library routines that Kernighan and Plaugher give in "Software Tools >in Pascal". Anybody else like to see UNIX translated to Pascal? I must admit it's been a pet dream of mine for quite some time. Alastair Milne