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 35ae339
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions docs/New Operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,13 @@ This operator does not implement any metamethods.
## Walrus Operator
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
```pluto
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 35ae339

Please sign in to comment.