[swift-evolution] [Planning][Request] "constexpr" for Swift 5

Tino Heth 2th at gmx.de
Sun Jul 30 11:56:16 CDT 2017

> more elaborate compile-time facilities, which would also provide extremely powerful meta programming features
That's an interesting twist — but whenever you put a "meta" somewhere, things tend to get complicated, and people end up with different associations to the topic… ;-)
I took a brief look at the C++ document, but it seemed still to much macro-like to me.

My take on the topic would be he ability to express common programming tasks (declaring a class, overriding a method…) in the language itself.
public class ProxyViewController: UIView {}
Could be written as
let subclass = createClass(classname: "ProxyViewController", superclass: UIViewController, accessLevel: .public)

Quite stupid at first sight, and basically the exact opposite of syntactic sugar ("syntactic salt" already has a meaning… so I'd call it "syntactic pepper" ;-).
But now imagine that:

for (method, implementation) in UIViewController.methods where method.accessLevel == .open {
    subclass.methods[method] = { parameters in
        print("Subclass method \(method) called with \(parameters)")
        return implementation(parameters)

Not that stupid anymore, isn't it?
I think this would be way cooler than poking around with variants of search & replace…

- Tino

(to get syntax colouring, I wrote ~30 lines of Swift that turn the straw man example into valid code… it's fun, maybe I play with it a little bit more ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170730/b10791c4/attachment.html>

More information about the swift-evolution mailing list