[swift-evolution] [Idea] if let value!

Vladimir.S svabox at gmail.com
Wed May 18 08:35:34 CDT 2016


I understand *your* idea of let?/let! etc without 'if', but personally I 
don't support it. I think `if` must be used in this feature.

In any case I feel like this idea is not accepted by community, so it seems 
like there is no sense to discuss its details.

On 18.05.2016 16:12, Daniel Höpfl wrote:
> That's the idea of "let?".
> "let!" would always execute the block (and crash if the optional is nil.)
>
> "if let!" is meaningless: "let!" would be true (if the optional is set) or
> crash (if the optional is nil).
>
> On 2016-05-18 14:27, Vladimir.S wrote:
>> The idea to process the 'if' block only if anOptional is not null
>>
>> In case of
>> let! anOptional {
>> }
>> IMO it is not clear that this block will be executed *only* if
>> anOptional is not null.
>>
>> if let! anOptional {
>>  // here only if anOptional != null
>> }
>> - seems like similar to standard 'if let' construction so should not
>> confuse too much and IMO will be remembered after the first
>> appearance/using.
>>
>> On 18.05.2016 15:15, Daniel Höpfl via swift-evolution wrote:
>>> Would it be possible to drop the "if"? I don't see why we need it.
>>>
>>> On 2016-05-18 11:22, LM wrote:
>>>> I am experimenting with this:
>>>>
>>>> If var! anOptional {
>>>>    anOptional   // unwrapped, shadowing
>>>> }
>>>>
>>>> if let! anOptional {
>>>> ... // same
>>>> }
>>>>
>>>>
>>>> This compiler codebase is truly remarkable, so it should also works with
>>>>
>>>> If var! opt1 where opt1 < 27 {
>>>> }
>>>>
>>>> or
>>>>
>>>> if var! opt1, opt2 {
>>>>    // both unwrapped
>>>> }
>>>>
>>>> LM/
>>>>
>>>>
>>>>> On May 18, 2016, at 10:21 AM, Daniel Höpfl via swift-evolution
>>>>> <swift-evolution at swift.org> wrote:
>>>>>
>>>>> Just an idea: Why don’t we think about it similar to try?
>>>>>
>>>>> var anOptional : String?
>>>>>
>>>>> let? anOptional { /* use it, but cannot change it */ }
>>>>> let! anOptional { /* use it, without checking, cannot change it */ }
>>>>>
>>>>> var? anOptional { /* use it, can also change it, */ }
>>>>> var! anOptional { /* use it, without checking, can also change it */ }
>>>>>
>>>>> Is it allowed to set it to nil in the var case? Hard to say.
>>>>>
>>>>>> On 17.05.16 15:43, Vladimir.S via swift-evolution wrote:
>>>>>> It is common to shadow optional value name with unwrapped value with
>>>>>> same name:
>>>>>>
>>>>>> if let someGoodValue = someGoodValue {...}
>>>>>>
>>>>>> What if we'll have a syntax to not repeat the variable name to achieve
>>>>>> the same target:
>>>>>>
>>>>>> if let someGoodValue! {...}
>>>>>>
>>>>>> What do you think?
>>>>>> _______________________________________________
>>>>>> swift-evolution mailing list
>>>>>> swift-evolution at swift.org
>>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>>> _______________________________________________
>>>>> swift-evolution mailing list
>>>>> swift-evolution at swift.org
>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>


More information about the swift-evolution mailing list