Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-12 Thread Taras Zakharko via swift-evolution
There is some truth in every joke ;) I do like goto though. It makes my C code cleaner and easier to maintain. But given that Swift already has a very reasonable restricted goto mechanism with labels, I am as happy as it gets :) — T > On 12 Jul 2016, at 18:21, Douglas Gregor

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-12 Thread Douglas Gregor via swift-evolution
> On Jul 12, 2016, at 9:20 AM, Taras Zakharko wrote: > > I’d love to see goto in Swift, but on the other hand, do {} with labels have > so far been sufficient for any practical problem I encountered so far. Goto > is much more useful in languages like C, which lack

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-12 Thread Taras Zakharko via swift-evolution
I’d love to see goto in Swift, but on the other hand, do {} with labels have so far been sufficient for any practical problem I encountered so far. Goto is much more useful in languages like C, which lack nested functions and other abstraction mechanisms. Of course, I wouldn’t try to write a

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-12 Thread David Hart via swift-evolution
Starting to know Erica, I think it was a joke, not to be taken seriously :) > On 12 Jul 2016, at 18:07, Leonardo Pessoa via swift-evolution > wrote: > > I'd agree with Doug, completely out of scope. The only way I'd support > a goto statement was to jump to another

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-12 Thread Leonardo Pessoa via swift-evolution
I'd agree with Doug, completely out of scope. The only way I'd support a goto statement was to jump to another switch case as in C#. L On 12 July 2016 at 12:49, Douglas Gregor via swift-evolution wrote: > > On Jul 12, 2016, at 8:47 AM, Erica Sadun via swift-evolution

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-12 Thread Douglas Gregor via swift-evolution
> On Jul 12, 2016, at 8:47 AM, Erica Sadun via swift-evolution > wrote: > > >> On Jul 11, 2016, at 4:49 PM, Chris Lattner > > wrote: >> >> As for all of the other additive changes, I would strongly prefer you to >>

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-12 Thread Daniel Steinberg via swift-evolution
Love that! > On Jul 12, 2016, at 11:47 AM, Erica Sadun via swift-evolution > wrote: > > >> On Jul 11, 2016, at 4:49 PM, Chris Lattner > > wrote: >> >> As for all of the other additive changes, I would strongly prefer

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-12 Thread Erica Sadun via swift-evolution
> On Jul 11, 2016, at 4:49 PM, Chris Lattner wrote: > > As for all of the other additive changes, I would strongly prefer you to > *wait* on even proposing or discussing these things until after the Swift 3.0 > evolution cycle is done. Not only is it distracting for the

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-12 Thread John McCall via swift-evolution
> On Jul 11, 2016, at 3:49 PM, Chris Lattner via swift-evolution > wrote: > As for all of the other additive changes, I would strongly prefer you to > *wait* on even proposing or discussing these things until after the Swift 3.0 > evolution cycle is done. Not only

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-11 Thread Leonardo Pessoa via swift-evolution
I'll have to give this a -1. Code seems to be confusing with this new use of continue and we may easily lose control of the flow. If we are to allow another case to be executed, we should be able to explicitly direct the flow to the case we want. C# does that using the goto keyword (yes, I know).

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-11 Thread Erica Sadun via swift-evolution
> On Jul 11, 2016, at 7:27 AM, Rob Mayoff wrote: > > Just to be clear, under your proposal, what does the following program > print? Can you make an argument in favor of your interpretation? > >var x = 1 >switch x { >case 1: >print("one") >x = 2 >

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-11 Thread Erica Sadun via swift-evolution
> On Jul 11, 2016, at 4:49 AM, Ross O'Brien wrote: > > I'm in favour of this concept being available in Swift, but it does need to > make a clear distinction somewhere between a case which matches anything (and > can catch any fallthrough/continue) and a case

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-11 Thread Rob Mayoff via swift-evolution
Just to be clear, under your proposal, what does the following program print? Can you make an argument in favor of your interpretation? var x = 1 switch x { case 1: print("one") x = 2 continue case 2: print("two") default: break }

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-11 Thread Ross O'Brien via swift-evolution
I'm in favour of this concept being available in Swift, but it does need to make a clear distinction somewhere between a case which matches anything (and can catch any fallthrough/continue) and a case which matches none of the above. I don't know whether we need to introduce an explicit term for

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-11 Thread Haravikk via swift-evolution
I'm a bit undecided about this feature, as I think it's harder to read the switch statement. For example, with this new feature I could write something like so: switch x { case 1: print("1") case 2:

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-11 Thread Jacopo Andrea Giola via swift-evolution
Here we go again :) I’m obviously supporting this proposal, like the first one we had tried to pass at the beginning of the swift evolution mailing list, even if in those times, we try to completely replace the fallthrough keyword with a new one. I continue to have a draft of that proposal on

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-11 Thread G B via swift-evolution
I like this idea. Remember that `continue` can typically take an optional argument that allows a type of “goto” functionality. Would it work to allow the `continue` target to be a labeled `case`? This could allow for some rather sophisticated logic without needing to duplicate a lot of code

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-11 Thread Jacob Bandes-Storch via swift-evolution
Wouldn't that be served better by `case let (x?, y?) where validate(x) && validate(y)` ? Jacob On Sun, Jul 10, 2016 at 11:39 PM, Xiaodi Wu via swift-evolution < swift-evolution@swift.org> wrote: > Or, less contrived, based on code I just wrote today (and refactored, > because this doesn't work

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-11 Thread Xiaodi Wu via swift-evolution
Or, less contrived, based on code I just wrote today (and refactored, because this doesn't work today), given two optionals a and b: ``` let c: Foo? switch (a, b) { case let (x?, y?): if validate(x) && validate(y) { c = x & y // yes, bitwise and continue } fallthrough case let (x?,

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-11 Thread Xiaodi Wu via swift-evolution
switch fourSidedShape { case rhombus: // do some rhombus-specific work if parallelogram ~= shape { continue } // do some other rhombus-specific but parallelogram-inapplicable work fallthrough case rhomboid: // do work the slow way // applies to all rhomboids including rhombuses unless

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-11 Thread Remy Demarest via swift-evolution
This is a great feature, and this is something that would allow the execution of multiple case statements that fallthrough does not currently allow. For example in today's world this is not allowed: func blah(point: CGPoint) { switch (point.x, point.y) { case (let x, _) where x > 10:

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-10 Thread Erica Sadun via swift-evolution
> On Jul 10, 2016, at 11:54 PM, Xiaodi Wu wrote: > > I disagree. First, in both cases there's an A and a B. The two scenarios we > are comparing are "if condition continue, else break" and "if condition > continue, else fallthrough". Both break and fallthrough are equally

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-10 Thread Xiaodi Wu via swift-evolution
I disagree. First, in both cases there's an A and a B. The two scenarios we are comparing are "if condition continue, else break" and "if condition continue, else fallthrough". Both break and fallthrough are equally control transfer experiments. Both of these scenarios add complexity for reasoning

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-10 Thread Erica Sadun via swift-evolution
> On Jul 10, 2016, at 11:42 PM, Xiaodi Wu wrote: > > Right. Both seem equally reasonable alternatives if a condition isn't > fulfilled where I'd like to continue pattern matching. Why do you say one of > these would be fair to disallow? I'm saying pick behavior A or

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-10 Thread Erica Sadun via swift-evolution
Because one says "consider the next case" and the other says "do not consider the next case" > On Jul 10, 2016, at 11:03 PM, Xiaodi Wu wrote: > > I know how it works. Why would you say that it's reasonable to prohibit > fallthrough when continue is used? The difference

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-10 Thread Xiaodi Wu via swift-evolution
I know how it works. Why would you say that it's reasonable to prohibit fallthrough when continue is used? The difference between it and break is that Swift chooses the latter to be implied, and obviously we cannot prohibit break. On Sun, Jul 10, 2016 at 23:51 Erica Sadun

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-10 Thread Erica Sadun via swift-evolution
> On Jul 10, 2016, at 10:34 PM, Xiaodi Wu wrote: > > > > On Sun, Jul 10, 2016 at 11:21 PM, Erica Sadun > wrote: >> On Jul 10, 2016, at 10:16 PM, Xiaodi Wu > > wrote:

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-10 Thread Xiaodi Wu via swift-evolution
On Sun, Jul 10, 2016 at 11:21 PM, Erica Sadun wrote: > On Jul 10, 2016, at 10:16 PM, Xiaodi Wu wrote: > Given patterns A, B, C, and D, suppose a value x matches A, C, and D, > whereas another value y matches B and D, and a third value matches B and >

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-10 Thread Xiaodi Wu via swift-evolution
On Sun, Jul 10, 2016 at 10:48 PM, Erica Sadun wrote: > > > On Jul 10, 2016, at 8:37 PM, Xiaodi Wu wrote: > > > > This is a neat idea, and I think a very sensible way to extend the > language. I worry only a little about the following: > > > >

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-10 Thread Erica Sadun via swift-evolution
> On Jul 10, 2016, at 8:37 PM, Xiaodi Wu wrote: > > This is a neat idea, and I think a very sensible way to extend the language. > I worry only a little about the following: > > Currently, unless preceded immediately by the keyword `fallthrough`, a > condition implicitly

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-10 Thread Erica Sadun via swift-evolution
> On Jul 10, 2016, at 8:36 PM, Taras Zakharko wrote: > > There is possible impact on existing code: a switch statement inside a loop, > that contains a continue. > > — Taras A switch statement within a loop may be broken by the introduction of `continue` semantics.

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-10 Thread Xiaodi Wu via swift-evolution
This is a neat idea, and I think a very sensible way to extend the language. I worry only a little about the following: Currently, unless preceded immediately by the keyword `fallthrough`, a condition implicitly excludes all previous conditions. That is, if I write `switch .. { case a: ...; case

Re: [swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-10 Thread Taras Zakharko via swift-evolution
There is possible impact on existing code: a switch statement inside a loop, that contains a continue. — Taras > On 11 Jul 2016, at 04:27, Erica Sadun via swift-evolution > wrote: > > A quick pitch to introduce `continue` to switch statements. This would be >

[swift-evolution] [Pitch] Introduce continue to switch statements

2016-07-10 Thread Erica Sadun via swift-evolution
A quick pitch to introduce `continue` to switch statements. This would be additive and could not be considered for Swift 3. -- E Pitch: Introduce continue to Switch Statements Introduction This pitch completes the