[swift-evolution] [Proposal] function "return" optional keyword.
Félix Cloutier
felixcca at yahoo.ca
Sat Dec 19 22:43:10 CST 2015
Just food for thought: C# has a special syntax, inspired by its own lambda syntax, for single-expression functions:
> // lambda syntax
> param => param + 4
>
> // single-expression method syntax
> int AddFour(int param) => param + 4;
Swift's syntax for declaring functions and lambdas are harder to link like that though.
Félix
> Le 19 déc. 2015 à 23:26:49, Jordan Rose via swift-evolution <swift-evolution at swift.org> a écrit :
>
> I'm not going to go as far as a definitive +1, but I've definitely wanted this for var and subscript getters. If it were limited to single-expression functions, I don't see much harm. The only time there'd be a problem is if the return types matched and you were going to have another statement instead.
>
> It feels weird for anything imperative, but I think the whole point is that there are plenty of functions which do absolutely no imperative work. I personally wouldn't want people to start using it for forwarding imperative things, though.
>
> func sendHTTPRequest() -> Result {
> sendHTTPRequestImpl(destinationURL, body)
> }
>
> Jordan
>
>
>> On Dec 19, 2015, at 5:30 , Craig Cruden via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>
>>
>> When writing short functional code in a function it would be nice if the return keyword were an optional keyword.
>>
>> Just return the last evaluated expression.
>>
>>
>> i.e.
>>
>> func flipFunc<T, U>(arg1: T, arg2: U) -> (U, T) {
>> (arg2, arg1)
>> }
>>
>>
>> The keyword return would still be there for breaking out of a function.
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto: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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151219/59a0cb1a/attachment.html>
More information about the swift-evolution
mailing list