File tree Expand file tree Collapse file tree 1 file changed +7
-16
lines changed
Expand file tree Collapse file tree 1 file changed +7
-16
lines changed Original file line number Diff line number Diff line change @@ -106,22 +106,13 @@ This operator does not implement any metamethods.
106106## Walrus Operator
107107The 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")
125116end
126117```
127118
You can’t perform that action at this time.
0 commit comments