Skip to content

Commit

Permalink
Document walrus operator for ifstat more clearly
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Nov 17, 2024
1 parent d199a53 commit f8510b8
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions docs/New Operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,12 @@ This operator does not implement any metamethods.
The Walrus operator allows you to perform assignments inside of conditional expresssions.

```pluto norun
if a := get_value() then
-- 'a' was assigned a truthy value.
else
-- 'a' was assigned a falsy value.
end
```
You can imagine it like this, but note they're not always the same:
```pluto norun
do
local a = get_value()
if a then
-- 'a' was assigned a truthy value.
else
-- 'a' was assigned a falsy value.
end
local get_value = || -> 1
if val := get_value() then -- scope of 'val' begins
print("got value: "..val)
else -- scope of 'val' ends
print("got no value")
end
```

Expand Down

0 comments on commit f8510b8

Please sign in to comment.