Accessing parts of arrays

Gregory Lypny gregory.lypny at videotron.ca
Wed Sep 29 12:07:05 EDT 2004


Hello everyone,

In doing some statistical work, it occurred to me that Revolution's 
arrays would be greatly enhanced if we could access sub-arrays just 
like we can with itemized and line-delimited lists.

For example, in a comma-delimited list of the natural numbers, 1 to 10, 
we can compute the average of any subset of the numbers using the 
average() function:

put "1,2,3,4,5,6,7,8,9,10" into x
put average(item 1 to 4 of x) && \
average(x) && \
average(item 1 to 8 of x) --yields 2.5, 5.5 and 4.5.

But as far as I know, we cannot refer to element 1 to 4 of array x, and 
we can only take the average of all the values in x to get 5.5 as 
below.

multiply t by 0
repeat 10 times
add 1 to t
put t into x[t]
end repeat
put average(x) -- yields 5.5

	Greg



More information about the use-livecode mailing list