0

Ok, let me start off by saying I am a super newbie in Standard ML. I am literally just beginning to program in this language. To be honest with you, I don't plan on digging too deep in this language. I just need to accomplish a one-time task and move on.

I am trying to tackle how to make a simple Array. Believe it or not, the documentation is confusing me to the point I cannot make a simple Array.

So it seems in order to do an array in sml New Jersey...I need to assign the maxLen variable. I simply assigned it 24 for now, but perhaps the way I am doing it is not working.

Let's say I am trying to create an array of 12 spots, with init values of 5.

val maxLen = 24;  (*assigning maxLen 24 as the largest array possible*)

array (12, 5);   (*Creating an Array of 12 spots with value of 5 for each*)

What am I missing here?

Majid Parvin
  • 4,499
  • 5
  • 29
  • 47
Busta
  • 81
  • 9

1 Answers1

2
val a = Array.array (12, 5)

works just fine. You don't need to "set" Array.maxLen, nor can you. That is merely an implementation-specific constant telling you what the maximum size of an array on the executing system is.

Also, be aware that you cannot grow an array. Arrays are a basic datatype that once created has a fixed size. If you need dynamic growth then you need to build a dynamic data structure around that (or use a library that provides it).

Andreas Rossberg
  • 34,518
  • 3
  • 61
  • 72