Swift: Trailing literal syntax
| Originator: | rix.rob | ||
| Number: | rdar://19775420 | Date Originated: | 09-Feb-2015 08:27 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode-Beta (6D520o) |
| Classification: | Enhancement | Reproducible: | Always |
Summary:
About ten years ago, I wrote my first language, Locus. It was _terrible_, but it had this one neat syntactic feature I liked: trailing literal syntax (tho only for unary functions):
foo [ 1, 2, 3 ] # calls foo, passing in an array
foo { bar: quux } # calls foo, passing in a dictionary
I just realized that this would be a pretty neat fit for Swift & its trailing literal syntax, although I suppose it would probably force whitespace as disambiguation from subscripting, which might be undesirable or infeasible. (I.e. subscripting would have to be foo[bar], trailing literal would have to be foo [bar]—note the space).
Steps to Reproduce:
N/A
Expected Results:
N/A
Actual Results:
N/A
Regression:
N/A
Notes:
You could have foo be a property which returns a variadically-subscriptable struct:
var foo: Subscriptable<T, U> {
return Subscriptable { things in
// do whatever with the things
}
}
struct Subscriptable<T, U> {
init(_ trampoline: [T] -> U) { … }
subscript(things: T...) -> U {
return trampoline(things)
}
}
foo [ "such", "a", "hack" ]
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!