Skip to content

Commit 7b6e90f

Browse files
committed
doc: be explicit about the short-circuiting behavior
1 parent 0b419bb commit 7b6e90f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

ppcs/ppc0021-optional-chaining-operator.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ is equivalent to:
100100

101101
with the important caveat that EXPR1 is only evaluated once.
102102

103+
When used in a longer chain of dereferences, an undef value will short-circuit the entire
104+
chain, rather than just a single expression:
105+
106+
EXPR1 ?-> EXPR2 ?-> EXPR3
107+
108+
is equivalent to:
109+
110+
```perl
111+
if (defined EXPR1) {
112+
if (defined EXPR1->EXPR2) {
113+
return EXPR1->EXPR2->EXPR3
114+
} else {
115+
return ()
116+
}
117+
} else {
118+
return () # empty list
119+
}
120+
```
121+
103122
## Backwards Compatibility
104123

105124
All code with `?->` currently yields a compile time syntax error, so there

0 commit comments

Comments
 (0)