Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!adm!wsmith@b.cs.uiuc.EDU From: wsmith@b.cs.uiuc.EDU Newsgroups: comp.lang.pascal Subject: Pascal User Manual and Report Message-ID: <11899@brl-adm.ARPA> Date: 19 Feb 88 00:31:28 GMT Sender: news@brl-adm.ARPA Lines: 61 >I was just looking at Jensen & Wirth's _Pascal User Manual and Report_. >In the section on the AND and OR operators, it says: > >"Assume for example, that x=0. Then > (x>0) and (x<10) >is already known to be false after computation of the first factor, and the >scond need not be evaluated. The rules of Pascal neither require nor forbid > ^^^^^^^^^^^^^^^ >the evaluation of the second part in such cases." > >Is this still true in the "current definition" of Pascal. All of the >implementations I've found will evaluate the second part. In fact, I believe >most people think that it the evaluation of the second part _is_ required. I tried this on my system where the second part is in fact NOT evaluated! I believe it points out quite clearly the problem that you stated. We are running VS Pascal under VM. pas side The SIDE LISTING and TEXT files will be put on the A minidisk INVOKING PASCAL/VS R2.2 NO COMPILER DETECTED ERRORS Source lines: 16; Total time: 0.05 seconds; Total rate: 19200 LPM EXECUTION BEGINS... FALSE 2 TRUE 1 R; type side pascal program side; var x:integer; function side_effect:boolean; begin x:=1; side_effect:=true end; begin termout(output); x:=2; if (x<2) and side_effect then writeln(True,x) else writeln(False,x); x:=2; if (x<3) and side_effect then writeln(True,x) else writeln(False,x); end. >What if the second part of the AND expression has side effects? If my >reading of Jensen & Wirth is correct, the result of any program with such >side effects is undefined in Pascal! Is this conclusion true? It certainly >isn't a pleasant one since there is probably plenty of code that depends on >the evaluation of the second part being required. I suppose that this program would have different results via your compiler. --------------------------------------------------------------------- Tim Margush R1TMARG@AKRONVM.BITNET (216) 375-7109 Department of Mathematical Sciences University of Akron Akron, OH 44325