🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pl1
Article #20

Short-circuiting IF statements

#20
From: Peter Flass
Date: Sat, 17 Oct 2026 20:06
47 lines
2897 bytes
The PL/I standard specifies that all expressions in an IF-Statement are 
evaluated to determine truth or falsity. However the IBM Enterprise PL/I 
Language Reference says:

The test of the IF expression is short-circuited under the following 
circumstances:
• If the IF expression consists of a logical OR of 2 expressions and the 
first of these expressions is true,
the second expression will not be evaluated and the code will execute 
the THEN clause.
• If the IF expression consists of a logical AND of 2 expressions and 
the first of these expressions is false,
the second expression will not be evaluated and the code will execute 
the ELSE clause.

Iron Spring PL/I currently short-circuits. I have tested Windows PL/I 
and Multics PL/I and they don't. I am attaching a small program to test 
this. I'd appreciate it if someone could compile it with whatever PL/I 
compiler you have and let me know the results. If it short-circuits you 
should get two lines of output: "zero" and "one"; if it does not you 
should get four.

Normally this is not a problem, except for two cases:
1. Evaluation of the second part of the expression depends on the first 
being true or false, for example "if p¬null & p->"...
2. One or more of the expressions has side-effects, as in the following 
example.

  ---------- the program ----------
/* Test shortcut IF-Statements */
if : Procedure options ( main ) ;
zero: proc returns( bit(1) );
  put skip list('zero');
  return(0);
  end zero;
one: proc returns( bit(1) );
  put skip list('one');
  return(1);
  end one;

  if 0 & zero() then /*nothing*/ ;
  if 1 & zero() then /*nothing*/ ;
  if 0 | one()  then /*nothing*/ ;
  if 1 | one()  then /*nothing*/ ;

End if ;
Technical Details
Message-ID: <11b0kgn$iefc$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Peter Flass <Peter@Iron-Spring.com>
Newsgroups: comp.lang.pl1
Subject: Short-circuiting IF statements
Date: Sat, 17 Oct 2026 13:06:45 -0700
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <11b0kgn$iefc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 17 Oct 2026 20:06:48 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="604652"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19N68/cSsV+ETBCbFrgDToi"; posting-host="aaf620107cbff3d328cde10b3050d04f"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:JpMHrprMocZ3UbUrQWWb/o15kzU= sha256:o5ZD9piCp3qD80HxiFbv0ZV3gSL53IQqi2qZL24rl/s=
	sha1:bQBuGzx59VsMiar+7peLYrtUJVs= sha256:2PV0hENnwYcIOJ/6/nHAW6pZcfqspV0ImhzeOS82chM=
Content-Language: en-US