Working on a little utility to generate 65C02 ROM images, I had this thought that it would be nice to be able to express a sub-array replacement as an array assignment, something like this:
var rom = [UInt8](repeating: 0xea, count: 32768) rom[0x6000] <= [ 0x01, 0x02, 0x03 ]
The result of the above code would be equivalent to:
rom[0x6000] = 0x01 rom[0x6001] = 0x02 rom[0x6002] = 0x03
But I couldn't think of a way to implement this fictitious
<= operator. I can see a way to do it like this:
rom <= (0x6000, [ 0x01, 0x02, 0x03 ])
but that's not really any better than
It may be silly to want to do this, it was just an idea I had, and made me wonder what was possible in Swift.
(I’m also not sure how to implement something like this for generics like Array).