Short-circuit evaluation: Difference between revisions
Content added Content deleted
(→Icon and Unicon: comments) |
(→{{header|Icon}}: better example) |
||
Line 126: | Line 126: | ||
==={{header|Icon}}=== |
==={{header|Icon}}=== |
||
<lang Icon>procedure main() |
<lang Icon>procedure main() |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
write("i,j := ",image(i),", ",image(j)) |
write("i,j := ",image(i),", ",image(j)) |
||
write(" |
write("i & j:") |
||
x := |
x := i() & j() |
||
write(" |
write("i | j:") |
||
y := |
y := i() | j() |
||
} |
} |
||
end |
end |
||
⚫ | |||
procedure a(x) #: returns x if x is non-null or fails otherwise |
|||
return |
return |
||
end |
end |
||
procedure false() |
|||
fail # for clarity but not needed as running into end has the same effect |
|||
end |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
rtcircuit.icn: 8 | false() |
|||
⚫ | |||
⚫ | |||
⚫ | |||
rtcircuit.icn: 16 | true returned &null |
|||
i,j := procedure true, procedure true</pre> |
|||
⚫ | |||
return \x |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
shortcicuit.icn: 12 | a(&null) |
|||
shortcicuit.icn: 19 | a failed |
|||
⚫ | |||
⚫ | |||
==={{header|Unicon}}=== |
==={{header|Unicon}}=== |
||
The Icon solution works in Unicon. |
The Icon solution works in Unicon. |