Short Circuit Question

new topic     » topic index » view thread      » older message » newer message

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C3A9B4.70253580
	charset="iso-8859-1"

Can someone exlain why line to of the output actually tests both 1 and 3,
shouldn't just test 1?
is it interpreted as ((1 or 2) and 3) or as (1 or (2 and 3)) ?
Daniel Kluss

----------output
1 2 3 true
1 3 true
1 true
1 2 true
-----------program

without warning
function ptr(atom num)
        printf(1,"%d ",{num})
        return num
end function

if ptr(1) and ptr(2) and ptr(3) then puts(1,"true\n") else puts(1,"false\n") end
if

if ptr(1) or ptr(2) and ptr(3) then puts(1,"true\n") else puts(1,"false\n") end
if

if ptr(1) or ptr(2) or ptr(3) then puts(1,"true\n") else puts(1,"false\n") end
if

if ptr(1) and ptr(2) or ptr(3) then puts(1,"true\n") else puts(1,"false\n") end
if

------=_NextPart_000_0005_01C3A9B4.70253580
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1264" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Can someone exlain why line to of the output 
actually tests both 1 and 3, shouldn't just test 1?</FONT></DIV>
<DIV><FONT face=Arial size=2>is it interpreted as&nbsp;((1 or 2) and 3) or as (1
or (2 and 3)) ?</FONT></DIV>
<DIV><FONT face=Arial size=2>Daniel Kluss</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>----------output</FONT></DIV>
<DIV><FONT face=Arial size=2>1 2 3 true<BR>1 3 true<BR>1 true<BR>1 2 
true<BR>-----------program</DIV></FONT>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>without warning<BR>function ptr(atom 
num)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(1,"%d 
",{num})<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return num<BR>end 
function</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>if ptr(1) and ptr(2) and ptr(3) then 
puts(1,"true\n") else puts(1,"false\n") end if</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>if ptr(1) or ptr(2) and ptr(3) then 
puts(1,"true\n") else puts(1,"false\n") end if</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>if ptr(1) or ptr(2) or ptr(3) then puts(1,"true\n")
else puts(1,"false\n") end if</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>if ptr(1) and ptr(2) or ptr(3) then 

------=_NextPart_000_0005_01C3A9B4.70253580--

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu