[swift-evolution] Lambda function syntax

Craig Cruden ccruden at novafore.com
Thu Dec 24 07:35:37 CST 2015


Assuming that you are using : for type assignment and -> or => for functions

unlabelled functions would have the syntax  Int => Int not Int: Int.

So func(int : Int, bool: Bool) : Int  // would return a value

func((int: Int, bool: Bool) : Int => Int would return a function with parameter of int and and a function f(i) -> int.


> On 2015-12-24, at 19:38:37, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> I'm completely against replacing '->' by ':' it would make unreadable the declaration of a function taking a closure as parameter, or returning one (among other things).
> 
> Actually, I find this perfectly readable, though a little bit strange after so long with the current signatures:
> 
> 	func indexOf(predicate: Element: Bool): Index? {
> 		for (i, elem) in zip(indexes, self) {
> 			if predicate(elem) {
> 				return i
> 			}
> 		}
> 		return nil
> 	}
> 
> Where I *do* foresee big issues is with tuples. Take a look at this declaration:
> 
> 	let tuple: (Int: Int, Bool: Bool)
> 
> Does `tuple` contain two unlabeled functions, or two labeled values?
> 
> -- 
> Brent Royal-Gordon
> Architechies
> 
> _______________________________________________
> 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