[swift-evolution] [DRAFT] Regularizing Where Grammar (was Re: Add a while clause to for loops)
Xiaodi Wu
xiaodi.wu at gmail.com
Fri Jun 10 15:26:26 CDT 2016
On Fri, Jun 10, 2016 at 3:15 PM, Thorsten Seitz via swift-evolution <
swift-evolution at swift.org> wrote:
> -1
>
> Am 10.06.2016 um 21:10 schrieb Brent Royal-Gordon via swift-evolution <
> swift-evolution at swift.org>:
>
> if case .some(let Point.cartesian(x, y)) where x < y =
> json["rect"]?["origin"].flatMap(.init(rawValue:)) { … }
>
>
> This: `where x < y = json[…]` is *very* unreadable and probably
> unparseable as it is missing a delimiter between the boolean expression and
> the expression behind the assignment operator. And I do not count the
> assignment operator as a sufficient delimiter.
>
Agreed. Unless this readability issue can be solved, I'm concerned about
this particular reshuffling.
>
> I’ll give the following counterargument against this shuffling around of
> `where` or trying to eliminate it:
>
> if case .some(let x) = someExpression where x > 0
>
> for x in xs where x > 0
>
> These are actually very consistent in their grammar when you look at it
> like follows:
>
> <target> <assignment op> <source> where <condition>
>
>
> if case .some(let x) = someExpression where x > 0
>
> target: `case .some(let x)`
> assignment op: `=`
> source: `someExpression`
> condition: `x > 0`
>
>
> for x in xs where x > 0
>
> target: `x`
> assignment op: `in`
> source: `xs`
> condition: `x > 0`
>
>
> That is I’m arguing the `where` grammar is already quite regular and
> should not be changed. And yes, I’d like to have `where` back in `case`.
> And `let`.
>
The inconsistency argument is that this grammar is inconsistent with usage
when switching over cases, etc., not that it's inconsistent with usage in
`if`.
Principally, though, the problem is that `where` leaves implied but
unanswered the question of "what happens where not?" For an `if` statement
the answer is inherent to the word "if," but because it is inherent, it
becomes redundant and can be replaced with a comma. Likewise `while`. For a
`for` loop, `where` cannot be replaced with a comma because it is not
implied by the word `for`; but because it is not redundant, it is also not
inherent in the meaning of the word "where."
>
> -Thorsten
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160610/b651bdcd/attachment.html>
More information about the swift-evolution
mailing list