Re: [swift-evolution] [Pitch] Guarding on enum values

2015-12-27 Thread Kevin Ballard via swift-evolution
You actually can do simple let-bindings in if-let and guard-let via the `case let` syntax: guard case let r = returnsResult(), case let .Succeed(m) = r else { ... } Although the problem with this is `r` still isn't visible inside of the else block, because it's part of the guard statement and

Re: [swift-evolution] [Pitch] Guarding on enum values

2015-12-27 Thread Thorsten Seitz via swift-evolution
> Am 28.12.2015 um 02:31 schrieb Kevin Ballard via swift-evolution > : > > You actually can do simple let-bindings in if-let and guard-let via the `case > let` syntax: > > guard case let r = returnsResult(), case let .Succeed(m) = r else { ... } > > Although the

Re: [swift-evolution] [Pitch] Guarding on enum values

2015-12-24 Thread Félix Cloutier via swift-evolution
Wait, no, there's a problem with that. You can't use `r` in the guard scope because `returnsResult()` might not have succeeded. Félix > Le 24 déc. 2015 à 09:37:36, Félix Cloutier via swift-evolution > a écrit : > > I like that it's consistent with the if syntax

Re: [swift-evolution] [Pitch] Guarding on enum values

2015-12-23 Thread Félix Cloutier via swift-evolution
I feel exactly like Brent. Félix > Le 23 déc. 2015 à 04:15:24, Brent Royal-Gordon via swift-evolution > a écrit : > >> guard case let .Succeed(m) = returnsResult() else { >>return it >> } >> // Can safely use m, otherwise Result is passed back the call

Re: [swift-evolution] [Pitch] Guarding on enum values

2015-12-23 Thread Andrew Duncan via swift-evolution
In fact, I feel the same way too. I have definite views about indefinite pronouns. When I am teaching, I studiously avoid “it”, “this”, and “that”: at any given instant half the students have wandering minds, and if they miss the referent, they get lost. My old HyperTalk habits must be

Re: [swift-evolution] [Pitch] Guarding on enum values

2015-12-23 Thread Andrew Duncan via swift-evolution
Yes, which would revert to Brent’s suggestion. But you have generalized it in a very compatible way. As I read somewhere, improving programming languages comes from removing limitations rather than adding features. I intend for this Pitch to be the former, although it does kind of look like

Re: [swift-evolution] [Pitch] Guarding on enum values

2015-12-23 Thread Andrew Duncan via swift-evolution
More progress! This sounds good, but it looks like what you intend is for r to be the error message in the Result enum type. enum Result { case .Fail(String)// Error message case .Succeed(MyType) // Something to work with } guard case let .Succeed(m) = returnsResult() else case let

Re: [swift-evolution] [Pitch] Guarding on enum values

2015-12-23 Thread Joe Groff via swift-evolution
> On Dec 23, 2015, at 3:56 PM, Andrew Duncan wrote: > > More progress! This sounds good, but it looks like what you intend is for r > to be the error message in the Result enum type. > > enum Result { > case .Fail(String)// Error message > case .Succeed(MyType) //

Re: [swift-evolution] [Pitch] Guarding on enum values

2015-12-23 Thread Brent Royal-Gordon via swift-evolution
> What about an enumeration with three cases? > > For example: > > enum Result { > case Success > case Failure > case Cancelled > } What about it? The case permitted by the `guard` continues through the surrounding scope; the other cases are handled by the `else` block. -- Brent

Re: [swift-evolution] [Pitch] Guarding on enum values

2015-12-23 Thread Step C via swift-evolution
> On Dec 22, 2015, at 11:58 PM, Andrew Duncan via swift-evolution > wrote: > > Motivation > > The guard statement rescues us from the pyramid of doom, and lets our code > hug the left margin more... if the failure case is false or nil. I'd like to > guard against

Re: [swift-evolution] [Pitch] Guarding on enum values

2015-12-23 Thread Brent Royal-Gordon via swift-evolution
>guard case let .Succeed(m) = returnsResult() else { > return it >} >// Can safely use m, otherwise Result is passed back the call stack. I didn't understand what you wanted to begin with, so to summarize: you want to be able to bind the return value of `returnsResult()` to a