Zulip Chat Archive

Stream: general

Topic: Update value in 2D array


Daniel Weber (Sep 28 2024 at 03:54):

I have a 2D array arr : Array (Array α) defined by let mut arr := .. and I want to set arr[i][j] = x. Currently I'm using arr := arr.set! i (arr[i]!.set! j x), but I'm not sure it doesn't copy arr[i], and it's also quite long to type.
Is there a better way to do this?

Eric Wieser (Sep 28 2024 at 09:42):

Can you use modify instead?

Kim Morrison (Sep 28 2024 at 12:29):

I wonder if we should just add set\_2.

Daniel Weber (Sep 28 2024 at 12:31):

Eric Wieser said:

Can you use modify instead?

I didn't know of that function, thanks. Should I use it like arr.modify i (fun a => a.set j x)?

Eric Wieser (Sep 28 2024 at 12:31):

Yes, that was what I was suggesting


Last updated: May 02 2025 at 03:31 UTC