[swift-evolution] Yet another fixed-size array spitball session

Charlie Monroe charlie at charliemonroe.net
Tue May 30 01:32:31 CDT 2017


Sorry if this has been suggested before, but what is wrong with something along

let x: Int[4]
let x: Int<4>

In case of multi-dimension arrays:

let x: Int[4][4]
let x: Int[4, 4]
let x: Int<4><4>
let x: Int<4, 4>

I see small issues with each that would need to be discussed - the first would disallow subscripts on types. Subscripts currently cannot be static, at least now anyway, though. The second syntax is too close to generics, which may be confusing...


> On May 29, 2017, at 11:39 PM, Nicolas Fezans via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
> On Mon 29. May 2017 at 20:57, David Sweeris via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
> > On May 29, 2017, at 01:12, Tino Heth via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> >
> > I agree strongly that the syntax looks awkward — imho
> > var v: Vector<Int, size: 3>
> > would be a much better fit than
> > var v array 3 of Int
> >
> > As much as I want to have "real" arrays, I don't think we should add new keywords for them.
> 
> Yeah, a "fixed-size array" is probably the most obvious use-case for allowing literal values to be generic parameters. In fact, at that point, they'd just be another type... no special support needed, other than validating the count when assigning array literals to them.
> 
> 
> The syntax that gained some traction last time they were seriously discussed would also be better, IMHO:
> let x: [Int x 4]
> or maybe it was this?
> let x: [Int * 4]
> Either way, it's more concise, far easier to read (IMHO), and doesn't need new keyword(s).
> 
> I have not followed all previous discussions on this (so sorry if it was already proposed and/or discussed) but from the point of view of the "standard mathematics writing", it seems to me that it should rather be [Int^4] .
> 
> Indeed the three dimensional space built by combining the set of real numbers R is noted R^3 or alternatively RxRxR (but for larger dimensions you certainly do not want this writing!)
> 
> Strictly speaking  Int^4  would be mathematically speaking more correct but  [Int^4]  has the advantage of making clear that this is indeed an array.
> 
> There are many aspects in the initial proposal that certainly need a more expert eye than mine. I have one question though. It seems to me that the constant expressions as known as constexpr in C++11 would be allowed as well. Is that right? If yes, are there any differences in the proposal to what is allowed in C++11? 
> 
> Nicolas
> 
> 
> 
> - Dave Sweeris
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170530/2a90be43/attachment.html>


More information about the swift-evolution mailing list