Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!haven!uvaarpa!virginia!scl From: scl@virginia.acc.virginia.edu (Steve Losen) Newsgroups: comp.lang.pascal Subject: Re: file windows (was Re: Standard Pascal) Message-ID: <2929@virginia.acc.virginia.edu> Date: 24 Jul 89 21:18:23 GMT References: <8616@pyr.gatech.EDU> <18965@paris.ics.uci.edu> <4623@freja.diku.dk> Reply-To: scl@virginia.acc.Virginia.EDU (Steve Losen) Organization: University of Va., Charlottesville, VA Lines: 58 In article <4623@freja.diku.dk> dat0@rimfaxe.diku.dk (Dat-0 undervisningsassistent) writes: >schwartz@shire.cs.psu.edu (Scott Schwartz) writes: >>Alastair Milne writes: >>| > 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 didn't say you don't commit to reading the the window variable. The >>thing you don't commit to is advancing the file pointer: commiting to >>read from the FILE. > >As somebody already have pointed out, "read(input, ch)" is exactly >equivalent to "ch:=input^;get(input)" (by definition of the ISO standard). > >The interesting thing about this is (IMHO) that using the filewindow you >can check what you are about to read, not just what you have already read. >I have seen a couple of examples, where this saves you a lot of trouble. > > ... > >Kristian Damm Jensen >(dat0@diku.dk) >Institute of datalogi, University of Copenhagen (DIKU) 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. -- Steve Losen scl@virginia.edu University of Virginia Academic Computing Center