Inline Meta-Programming

Especially when creating a DSL and static-let's, I find myself unavoidably writing repetitive code. It would be very helpful to have some small-scoped inline meta-programming options. Specifically, I suggest something like the following:

extension String {
    #repeat(["foo", "bar"]) { string in
        "static let \(string) = \(string.debugDescription)"
    }
}

This could be accomplished is adding support for closures in macros.

Macros already support trailing closures. See for example #expect(throws:).

1 Like

Oh, wonderful! Do you know of any example implementations I can see?