[swift-evolution] Proposal: Add "none" and simplify the language.

Joe Groff jgroff at apple.com
Thu Jan 7 12:11:23 CST 2016


> On Jan 7, 2016, at 9:56 AM, James Campbell <james at supmenow.com> wrote:
> 
> So what would none do for arrays ?
> 
> Would it auto initialize an empty array ? 
> 
> If so would love to play around with alternative key words

If I understand Amir correctly, they're proposing that 'none' place the variable in a dynamically invalid state, and the program will trap if the value isn't set before use.

-Joe

> 
> On Thu, Jan 7, 2016 at 5:50 PM, Joe Groff via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
> > On Jan 7, 2016, at 9:46 AM, Amir Michail via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> >
> > Examples:
> >
> > var x:Int = none // uninitialized but not an optional
> >
> > print(x) // run-time error as x is uninitialized
> >
> > if x == nil { … } // compile time error… x can never be nil because it is not an optional
> >
> > if x == none { x = 2 } // … but it can be uninitialized
> >
> > Optionals can also be uninitialized:
> >
> > var y:Int? = none // uninitialized and an optional
> >
> > if y == nil { … } // run-time error as y is uninitialized
> >
> > y = nil
> >
> > if y == nil { … } // fine
> 
> This use case should be supportable as a property behavior; check out the "delayed" example from my proposal:
> 
> https://gist.github.com/jckarter/f3d392cf183c6b2b2ac3 <https://gist.github.com/jckarter/f3d392cf183c6b2b2ac3>
> 
> -Joe
> _______________________________________________
> 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>
> 
> 
> 
> -- 
>  Wizard
> james at supmenow.com <mailto:james at supmenow.com>
> +44 7523 279 698

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


More information about the swift-evolution mailing list