Path: utzoo!attcan!uunet!ginosko!ctrsol!cica!gatech!psuvax1!schwartz From: schwartz@shire.cs.psu.edu (Scott Schwartz) Newsgroups: comp.lang.pascal Subject: Re: Standard Pascal Message-ID: Date: 6 Jul 89 07:02:00 GMT References: <8616@pyr.gatech.EDU> <18965@paris.ics.uci.edu> Sender: news@psuvax1.cs.psu.edu Lines: 41 In article <18965@paris.ics.uci.edu> milne@ics.uci.edu (Alastair Milne) writes: | mlw@pyr.gatech.EDU (Michael Williams) writes: | >Borland obviously left get and put out of turbo pascal for a reason. | >Can anyone tell me why get and put are better than read and write? | >Used in conjunction with the seek command, I find read/write almost | >identical to array access for a file of records, which is quite helpful. | | I don't know that GET and PUT are necessarily "better" than read or write, | but they are certainly more standard. Using them, I can transport typed | file I/O among a number of Pascal dialects; Turbo is the only one I know of | that overloads READ and WRITE, so it's the only one where that will work. 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) This works without side effects, so that it can be bundled up in a black box and called by anyone. Using read and write requires that the user maintain state information: global variables which get checked before doing any I/O. | As far as I'm aware, the principal impact of this substitution is that | porting things between Turbo and other dialects gets a little harder. I would say a lot harder. The example I give above makes it clear that you will have to add code to the application to duplicate the state info that the file variable normally maintains. This requres checking all calls to read and write to make sure they read from your pushed-back data if it is available. If you get paid by the hour, you've got it made. I'd start by typing in the unix stdio style library routines that Kernighan and Plaugher give in "Software Tools in Pascal". -- Scott Schwartz