msiism | `push(@nums, prompt("Please enter number {$n + 1}: "));` also works fine. | 00:01 | |
msiism has to /part now, but will view logs tomorrow. | 00:05 | ||
00:05
msiism left
|
|||
nahita3882 | @arr[$i + 1] = $val will also work, it will autovivify wherever you want; the missed spots, if any, are filled with the default value of the container ((Int) in this case) | 00:47 | |
15:28
dakkar joined
16:46
msiism joined
|
|||
msiism | I'm still having problems with adding elements to arrays using `@arr[$i + 1] = …`: termbin.com/xj6p | 17:17 | |
Doing it this way seems to add a potentially arbitrary number of empty arguments of type (Any) before the element I want to add. | 17:19 | ||
I just got I've seen `[Red (Any) (Any) (Any) Blue]`, for example, after using the above method to add "Blue" to an array that already contained "Red". | 17:21 | ||
nahita3882 | when you do @arr[$idx] = ..., there are 2 cases to consider: i) $idx is "in bounds", i.e., $idx < @arr.elems; in this case usual assignment to already-existing element | 17:24 | |
ii) $idx is "out of bounds", i.e., $idx >= @arr.elems; in this case, Raku will assign the value to $idxth index while making the array length $idx + 1. The in-between $idx - @arr.elems elements are filled with the default values | 17:25 | ||
for example: @arr is ["y", "e", "s"], then i do @arr[3] = "a", then @arr becomes ["y", "e", "s", "a"] | 17:26 | ||
there was no hole left behind, and it's as if we .pushed, no Any appearing ($idx is 3 and so is @arr.elems prior to assignment) | 17:27 | ||
another example: @arr is ["y", "e", "s"], then i do @arr[4] = "a", then @arr becomes ["y", "e", "s", (Any), "a"] | 17:28 | ||
msiism | Okay, $i was one off in my case. | ||
I had set its initial value to 1 instead of 0. | |||
Thanks for the explanation! | 17:31 | ||
nahita3882 | np | 17:33 | |
monkeyinthejuice | How do I coding video game character to JUMPING in Raku | 17:52 | |
18:35
msiism left
|
|||
librasteve | @.landyacht. - looks like we have an Ai troll here - please can you exclude them from the raku server | 19:28 | |
Shrek 5: The Dr Pepper Adventure: | |||
20:37
dakkar left
23:51
Manifest0 left
|