Skip to content

Commit 35ae339

Browse files
committed
Document walrus operator for ifstat more clearly
1 parent d199a53 commit 35ae339

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

docs/New Operators.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,13 @@ This operator does not implement any metamethods.
106106
## Walrus Operator
107107
The Walrus operator allows you to perform assignments inside of conditional expresssions.
108108

109-
```pluto norun
110-
if a := get_value() then
111-
-- 'a' was assigned a truthy value.
112-
else
113-
-- 'a' was assigned a falsy value.
114-
end
115-
```
116-
You can imagine it like this, but note they're not always the same:
117-
```pluto norun
118-
do
119-
local a = get_value()
120-
if a then
121-
-- 'a' was assigned a truthy value.
122-
else
123-
-- 'a' was assigned a falsy value.
124-
end
109+
```pluto
110+
local get_value = || -> 1
111+
112+
if val := get_value() then -- scope of 'val' begins
113+
print("got value: "..val)
114+
else -- scope of 'val' ends
115+
print("got no value")
125116
end
126117
```
127118

0 commit comments

Comments
 (0)