3 ms·
const var scores = [3, 2, 5]! scores[0.5] = 4 print(scores) //[3, 2, 4, 5]! Genius! This trivially solves the problem of reading integer and floating point
by pmontra 3y ago
const var scores = [3, 2, 5]!
scores[0.5] = 4
print(scores) //[3, 2, 4, 5]!
Genius! This trivially solves the problem of reading integer and floating point numbers from input and inserting them into a sorted array. Too bad there are no loops in this language.
(Remember that arrays start from -1.)
- layer8 3y agoI wonder what the behavior of scores[-2] = 4! is. Or, for that matter, of scores[-1.1] = 4! (Assuming that -2 and -1.1 haven’t been deleted.)
- humbugtheman 3y agoThe first one would place 4 at the start of the array. So would the second one. If you did the first, then the second one, two 4s would be placed at the start.
- layer8 3y agoBut arrays start at -1. How would that work?
- humbugtheman 3y agoYou can insert items before the start
- layer8 3y agoSo it’s not invariably true that arrays start at -1? They only start at -1 after an array literal assignment? You need to update the language description! ;)
- barnabee 3y agoPerhaps they start at -1 and proceed in both directions
- cdcarter 3y agoconst var scores = [3, 2, 5]! scores[0.5] = 4 print(scores) //[3, 2, 4, 5]! scores[-2] = 10 print(scores) //[10, 3, 2, 4, 5] print(scores[-1]) // 10 is how I interpret the spec, but I did not run this through the reference compiler yet.
- heavyset_go 3y agoLoops are a code smell.
- RGBCube 3y agoLoops are implemented using when: const var i = 10 when (i >= 0) { do_something() i = i - 1 }