mirror of
https://github.com/luau-lang/rfcs.git
synced 2025-04-04 18:41:00 +01:00
Update syntax-if-statements-initializers.md
`where` ~> `in`
This commit is contained in:
parent
548d4c8ba9
commit
544f99eed6
1 changed files with 9 additions and 9 deletions
|
@ -40,7 +40,7 @@ end
|
||||||
```lua
|
```lua
|
||||||
function PlayerControl:GetEntities()
|
function PlayerControl:GetEntities()
|
||||||
if self.RemovedSelf then
|
if self.RemovedSelf then
|
||||||
elseif local entity = self:TryGetEntity() where entity == nil then
|
elseif local entity = self:TryGetEntity() in entity == nil then
|
||||||
elseif local index = table.find(self.Instances, entity.Root) then
|
elseif local index = table.find(self.Instances, entity.Root) then
|
||||||
table.remove(self.Instances, index)
|
table.remove(self.Instances, index)
|
||||||
self.RemovedSelf = true
|
self.RemovedSelf = true
|
||||||
|
@ -62,8 +62,8 @@ If statements with initializers must match the below grammar. The variables decl
|
||||||
+ 'if' cond 'then' block {'elseif' cond 'then' block} ['else' block] 'end' |
|
+ 'if' cond 'then' block {'elseif' cond 'then' block} ['else' block] 'end' |
|
||||||
'for' binding '=' exp ',' exp [',' exp] 'do' block 'end' |
|
'for' binding '=' exp ',' exp [',' exp] 'do' block 'end' |
|
||||||
...
|
...
|
||||||
+ cond = 'local' binding '=' exp ['where' exp] |
|
+ cond = 'local' binding '=' exp ['in' exp] |
|
||||||
+ 'local' bindinglist '=' explist 'where' exp |
|
+ 'local' bindinglist '=' explist 'in' exp |
|
||||||
+ exp
|
+ exp
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ local function foo()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if local b = foo() where b == false then
|
if local b = foo() in b == false then
|
||||||
print(b, "truthy block")
|
print(b, "truthy block")
|
||||||
else
|
else
|
||||||
print(b, "falsy block")
|
print(b, "falsy block")
|
||||||
|
@ -103,7 +103,7 @@ end
|
||||||
|
|
||||||
`Output: true falsy block`
|
`Output: true falsy block`
|
||||||
|
|
||||||
When declaring multiple values inside of an initializer, the `where` clause is required.
|
When declaring multiple values inside of an initializer, the `in` clause is required.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ local function foo()
|
||||||
return true, false
|
return true, false
|
||||||
end
|
end
|
||||||
|
|
||||||
if local a,b = foo() where a and b then
|
if local a, b = foo() in a and b then
|
||||||
else
|
else
|
||||||
print'Hello World, from Luau!'
|
print'Hello World, from Luau!'
|
||||||
end
|
end
|
||||||
|
@ -148,12 +148,12 @@ Initializers increase the complexity of the language syntax and may obscure cont
|
||||||
|
|
||||||
# Alternatives
|
# Alternatives
|
||||||
|
|
||||||
A different keyword or token can be used in place of `where`.
|
A different keyword or token can be used in place of `in`.
|
||||||
|
|
||||||
Introducing a new contextual keyword can introduce complexity in the parser, and a different existing keyword like `in` or `do` could be used instead.
|
Rather than use `in`, we could introduce a new contextual keyword, or use a different existing keyword like `do`.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
if local a, b = foo() in b > a then
|
if local a, b = foo() do b > a then
|
||||||
print'Hello World, from Luau!'
|
print'Hello World, from Luau!'
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Reference in a new issue