Thread View: comp.lang.functional
2 messages
2 total messages
Started by Susan E Smith
Tue, 05 Jan 1993 19:49
Length of Arrays in SML
Author: Susan E Smith
Date: Tue, 05 Jan 1993 19:49
Date: Tue, 05 Jan 1993 19:49
29 lines
1656 bytes
1656 bytes
PROBLEM: I am using Standard ML (New Jersey), Version 0.66 and I am trying to use the Array function "length" to get the length of an array. I have defined my array using arrayoflist: eg. val My_Array = arrayoflist ["Hi","My","Name","Is","Bob"]; Now I want to use "length My_Array" to return the integer 5. The reference manual I am using, says that this can be done and that the function length is one that takes an array and returns an int. However, this gives me an error when I try it in my version of SML and when I type "length;" it tells me that length accepts a list and returns an int, eg. length My_List; returns the length of the list, My_List. I have tested this and this is the case. The discrepancy between my reference manual and my version of SML is not the major concern here, what I really want to know is: Is there a way to get the length of an array in the version of SML I am using. This is important to my application because I have a statement that says My_Array sub i where i is begin incremented; hence, once i is out of range for the array, I don't want the function to continue executing. Any help would be greatly appreciated. Susan ssmith@ug.cs.dal.ca
Re: Length of Arrays in SML
Author: Andrew Koenig
Date: Wed, 06 Jan 1993 09:28
Date: Wed, 06 Jan 1993 09:28
16 lines
990 bytes
990 bytes
In article <C0ECE1.Ju@cs.dal.ca> ssmith@ug.cs.dal.ca (Susan E Smith) writes: > PROBLEM: I am using Standard ML (New Jersey), Version 0.66 and I am trying > to use the Array function "length" to get the length of an array. The problem is that the built-in function "length" takes a list, as you found out. What you want is the "length" in the Array structure, which is therefore called Array.length: val My_Array = arrayoflist ["Hi","My","Name","Is","Bob"]; Array.length My_Array; should print 5. -- --Andrew Koenig ark@europa.att.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads