Skip to content

Commit f8510b8

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

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

docs/New Operators.md

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,12 @@ This operator does not implement any metamethods.
107107
The Walrus operator allows you to perform assignments inside of conditional expresssions.
108108

109109
```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
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)