Array Basics

Dar Scott dsc at swcp.com
Wed Feb 25 16:28:44 EST 2004


On Wednesday, February 25, 2004, at 08:48 AM, Bojsza wrote:

> on mouseUp
>   put empty into xArray
>   put empty into zArray
>   put "1 2 3" into xArray
>   split xArray by space -- create an array from a list (3x1 array)
>   put "2 3 4" into zArray -- create a 1x3 array
> matrixMultiply(xArray,zArray)
> put it into arrayOut
> end mouseUp

on mouseUp
   put "1,1:1;1,2:2;1,3:3" into x
   split x using ";" and ":"
   put "1,1:2;2,1:3;3,1:4" into y
   split y using ";" and ":"
   put matrixMultiply(x,y) into z
   combine z using ";" and ":"
   put z
end mouseUp

==>
1,1:20

In hindsight, I think this might be more readable using space instead 
of ";".


> 2. I know that I can go from a list to an array with the split 
> command. Can I go from an array to a list also using the split > command?

Use combine as Jeanne explained and used above.

> 3. Can I create an array with a variable ie a 3x1 array with angle as 
> a variable?
>
> atan(angle)
> cos(angle)
> sin(angle)

Yes and no.

You can make an array builder function that instantiates such an array 
for the angle provided at build.  Like this (off the top of my head):

function angleArray alpha
   put atan(alpha) into a[1,1]
   put cos(alpha)  into a[1,2]
   put sin(alpha)  into a[1,3]
   return a
end alpha

However, you might want to look at value().  You can evaluate a string 
and strings can be array elements.  Thus, you can have an array of 
expressions.  You can be as creative in expression processing as you 
want.

Dar Scott




More information about the use-livecode mailing list