[swift-dev] Hello!/Obs. Language Elements/extent Swift for loops/Tuples init. APL in Swift

Johan Jensen jj at johanjensen.dk
Sun Feb 14 13:26:28 CST 2016


>
> 4 Tuples:  please take a look at this code:
>
>  static var z: UInt8 = 0  // initalize tuple with 256 UInt8 values, bytes:
>
>
>     // Silly: why not an array instead of this.. a tuple is needed..
> length must be exact 256..
>     // know of no other way to create a tuple with 256 elements...
>     var midiDataTuple = (z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z,
> z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z,
>  z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z,
> z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z,
> z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z,
> z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z,
> z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z,
> z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z,
> z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z,
> z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z,
>  z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z,
> z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z, z)
>
>
>
>     func midiSend(status: Int, val1: Int, val2 :Int)
>     {
>         var midipacket = MIDIPacket()
>
>
>         midipacket.timeStamp = 0
>         midipacket.length    = 3
>         midipacket.data      = midiDataTuple
> //<-=<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
>
>         midipacket.data.0 = UInt8(status)
>         midipacket.data.1 = UInt8(val1  )
>         midipacket.data.2 = UInt8(val2  )
>
>
>         var midipacketlist = MIDIPacketList(numPackets: 1, packet:
> midipacket)
>
>
>         MIDIReceived(midiSource, &midipacketlist)
>     }
>
>
> I can't treat tuples as an array, which in this case would be handy to
> initialize all the tuple elements.
>
> IfTrue: Why are tuples the only data type to use for unmanaged byte
> arrays?
>

There's currently some work on a proposal for Contiguous Variables (A.K.A.
Fixed Sized Array Type)
<https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160125/007984.html>
which should help with the creation of tuples. (It can be read in a better
fashion on gmane
<http://thread.gmane.org/gmane.comp.lang.swift.evolution/4809>)

— Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160214/49737f38/attachment.html>


More information about the swift-dev mailing list