[swift-evolution] [Proposal] Lexical scope statement (with .. do)
Tino Heth
2th at gmx.de
Mon Dec 28 03:01:44 CST 2015
> method cascades
I thought there was some sort of showstopper that ended further discussion for Swift 3 — but seems it wasn't the fault of the archive that I didn't find that reason ;-)
I'll use the opportunity to talk about my major motivation to want cascades in Swift:
Several years ago, I was quite bored by Objective-C and did an inquiry what other languages I might like.
I considered exotic choices like Vala (reference counted, compiled), but despite my dislike for garbage-collected systems, I also looked at the JVM.
At that time, my feeling was that many people were deeply impressed by some goodies Groovy had to offer, but didn't want to give up the benefits of type safety.
One of the major selling point for a nice contender called "Kotlin" has been "type safe, Groovy-style builders", and their use case might become very important for Swift as well.
I'll just show an example:
let page = HTML().{
body.{
table.{
tr.{
td.text("Cell content")
td.text("Another cell")
}
}
div(color: .redColor()).text("Some text")
}
}
// basic principle: directly start a method cascade on computed properties
This piece of code (I'm not using the proposed "with"-syntax but a light-weight alternative that I'd prefer) could generate a complete HTML-page, ready to be send to a browser — and the syntax is much easier than the generated markup itself!
With Swift on Linux, I'm quite sure generating HTML will become a very important task for the language.
Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151228/1f8b907d/attachment.html>
More information about the swift-evolution
mailing list