[swift-evolution] ternary operator ?: suggestion

Craig Cruden ccruden at novafore.com
Sun Jan 17 18:52:28 CST 2016


Chris has said many things about switch as an expression:

"if/else and switch as expressions: These are conceptually interesting things to support, but many of the problems solved by making these into expressions are already solved in Swift in other ways. Making them expressions introduces significant tradeoffs, and on balance, we haven't found a design that is clearly better than what we have so far.”

It is an often requested and often (i.e. every time) rejected…. and has a very high bar to pass before it would be considered.  At a certain point there was a realization that what we were really doing was conditionally mapping from one set to another (whether the set was one value or many) — and we could provide the same functionality plus much more by focusing on a generalized solution (i.e. a design that is clearly better than what we have so far).

The thread/discussion of where this option started to be considered was the 8th of January.

map is an existing function and a mathematical/functional concept which if we allowed for case syntax partial function concept to conditionally map from one domain to another would cover both switch as an expression but in a more generalized way. IMHO.

Craig

> On 2016-01-18, at 7:34:04, Jacob Bandes-Storch <jtbandes at gmail.com> wrote:
> 
> Hi all,
> 
> I'm a little bit surprised that this discussion has lost track of the idea of turning "switch" into an expression rather than a control-flow statement. Chris has expressed that he and other team members would like to consider this.
> 
> It was discussed a bit on the original version of this thread:
> https://lists.swift.org/pipermail/swift-evolution/2015-December/000385.html <https://lists.swift.org/pipermail/swift-evolution/2015-December/000385.html>
> 
> And in "Control Flow Expressions":
> https://lists.swift.org/pipermail/swift-evolution/2015-December/000393.html <https://lists.swift.org/pipermail/swift-evolution/2015-December/000393.html>
> 
> I've seen this ternary-operator discussion branching out in various directions and yet it slowly seems to converge back on "make it as similar to the existing switch statement as possible".
> 
> Was switch-as-an-expression intentionally dropped from consideration, in favor of adding new syntax? If so, I may have missed that piece of the discussion, and would appreciate if someone could point me to it.
> 
> Thanks,
> Jacob
> 
> On Sun, Jan 17, 2016 at 4:08 PM, Craig Cruden via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> Another attempt on motivation to thread the needle.
> 
> https://github.com/cacruden/swift-evolution/blob/master/proposals/0000-Pattern-Matching-Partial-Function.md <https://github.com/cacruden/swift-evolution/blob/master/proposals/0000-Pattern-Matching-Partial-Function.md>
> 
>> On 2016-01-18, at 3:04:35, Charles Constant <charles at charlesism.com <mailto:charles at charlesism.com>> wrote:
>> 
>> I think examples are convincing, but ideally we would put most of them in separate document. 
>> 
>> Though I love reading about programming, I generally do it in a half-assed sort of way. Unless the writing is very blunt and clear, I don't really understand it until I need to do it myself. I doubt I'm the only person here like this. 
>> 
>> I badly want this proposal to gain traction (more so every time I find myself writing code that it could improve, which happens daily). I think the proposal ought to be short and sweet. I believe if we hold the reader's attention just long enough for them to understand what we're talking about, they'll be onboard. Once they're hooked, we have our second document with the list of examples.
>> 
>> It would also be great to have the "before snippet" and "after snippet" visually arranged side-by-side. I'm guessing markdown doesn't support this :(
>> 
>> 
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160118/b54b387b/attachment.html>


More information about the swift-evolution mailing list