Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!agate!darkstar!ucscc!gorn!filbo From: filbo@gorn.santa-cruz.ca.us (Bela Lubkin) Newsgroups: comp.lang.pascal Subject: Re: file windows (was Re: Standard Pascal) Message-ID: <1.filbo@gorn.santa-cruz.ca.us> Date: 30 Jul 89 14:17:43 GMT References: <2929@virginia.acc.virginia.edu> Organization: R Pentomino Lines: 58 In article <2929@virginia.acc.virginia.edu> scl@virginia.acc.Virginia.EDU (Steve Losen) writes: >Here's a good example of how convenient the file buffer variable is: > >Suppose you want to allow the user to input a bunch of integers, separated >by any sequence of non-numeric characters. For example, the following >atrocity is legal input: > >,,100 ,20, >, > > 30 >40,, 5050 >,,, > >The program should process the integers 100, 20, 30, 40, and 5050. >Here is a trivial piece of Standard Pascal that does the job correctly. > >while not eof do begin > if (input^ >= '0') and (input^ <= '9') then begin > read(number); > process(number); > end > else > get(input); >end > >I admit that for most programming languages it is possible to come up >with simple and elegant solutions to selected bizarre problems. Too >bad there isn't one language that is universally applicable. My experience with "Standard Pascal" is pretty ancient, but I think that at least in this case you are fooling yourself. The file buffer may be "convenient", but you're not actually using it -- you commit to reading the data whether or not it's a digit. A >simpler< and >more< elegant piece of Standard Pascal code that does the same thing is: while not eof do begin read(number); if (number >= '0') and (number <= '9') then process(number); { else don't do anything, thus disposing of the invalid char } end In >most< situations where you might use the file buffer, it's not difficult to store away the item in your own one-item buffer; in this case, not even that is necessary. There are also cases where the file buffer is really a Good Thing; I'm not trying to excuse Turbo Pascal's unfortunate omission. In general I think that there are very few places where a file buffer would be more useful than true random access as in TP, and if TP wasn't pretending to be Pascal I wouldn't mind the omission. As it stands, it's an annoying portability issue. >Steve Losen scl@virginia.edu >University of Virginia Academic Computing Center Bela Lubkin * * filbo@gorn.santa-cruz.ca.us CIS: 73047,1112 @ * * ...ucbvax!ucscc!gorn!filbo ^^^the slowest route R Pentomino * Filbo @ Pyrzqxgl (408) 476-4633 & XBBS (408) 476-4945