[swift-evolution] [Review] SE-0144: Allow Single Dollar Sign as a Valid Identifier

Brent Royal-Gordon brent at architechies.com
Thu Oct 20 17:42:31 CDT 2016


> On Oct 20, 2016, at 2:52 AM, Benjamin Spratling via swift-evolution <swift-evolution at swift.org> wrote:
> 
> struct Note {
> 	/// half-steps from middle-C, nil means the note is a rest
> 	var pitch:Int?
> 	//more properties
> 	init?(xmlNode: XMLNode) {
> 		if let pitchString:String = xmlNode.attributes[“pitch”], let pitchInt:Int = Int(pitchString) {
> 			pitch = pitchInt
> 		}
> 		//more code
> 	}
> }
> 
> I could go write an extension on String to provide a computed integer property, but I’m not just talking about one case, I’m talking about all cases where we convert to types in this way.
> 
> If “$” meant “identifier of result of previous expression”, I could write:
> 
> init?(xmlNode: XMLNode) {
> 	pitch = xmlNode.attributes[“pitch”]?Int($)
> 	//more code
> }

Pretty cryptic. What's wrong with this?

	pitch = xmlNode.attributes["pitch"].map { Int($0) }
-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list