21 Arrays (Part 1)

OCaml has arrays, which are very similar to arrays in any other language.

We can create an array by writing something that looks almost like a list!

To access a value at an array, we use dot notation. Arrays are zero-indexed.

If you try to index past the end of an array, you get an Invalid_argument exception:

To mutate a value at an array, you can use the left arrow (<-) syntax.

What if we wanted to implement vectors) with arrays?

What if we wanted to print out each value in the array? We can loop over them!

Note that we use Array.length to get the length of the array, and we deduct one beacsue they are off by one errors.

But there are more better, functional ways to do this. The array standard library provides Array.iter (hey, it's JavaScript's Array.prototype.map)

They Printf.printf function can make this even easier!

(For some reason, jupyter doesn't like Printf.printf, but trust me, this works)