Documentation & Books

Raymond Griffith rgriffit at ctc.net
Wed Jul 7 20:33:38 CDT 2004


On Wednesday, July 7, 2004, at 04:36  PM, Richard Gaskin wrote:

> Judy Perry wrote:
>
> > Here's my real problem:  I barely got a "D" in the linear
> > algebra class that dealt with matrices (which I am assuming
> > is similar if not identical to arrays).
>
> You beat me:  I got an F.  No kidding.
>
> Fortunately arrays are much simpler.

They are nice. I am working on Matrix functions that can go fast. I've 
even taken the inverse of 30x30 matrices. The project I am working on 
will eventually become a statistics/data analysis program for people 
who don't know much about it.

The biggest difficulty I have with arrays is the internal hash. When 
you split a list of more than nine items into an array, the order you 
get using "Combine" is mixed up. That is because the hash ordering is 
more alphabetic than it is numeric. So "1,2,3,4,5,6,7,8,9,10" gets 
returned as "1,10,2,3,4,5,6,7,8,9" .

What I would greatly love to see is allowing complex functions with 
arrays. For example, if xArr is an array, you can "multiply xArr by 2", 
or "put xArr - 3 into yArr", but you can't do things like "put ln(xArr) 
into yArr".


>
> > So, I am clueless.  I am one step ahead of a newbie who has
> > never heard the term before (and, hence, wouldn't know to
> > search for it, much less know what to do with any results)
> > in that I think I have a vague idea of what it is and what
> > it can be used to do (for example, keep track of character
> > stats in a game, including previous locations in which
> > something interesting was revealed or for the purposes of
> > map revelations/display and the like) but that's about it.
> > I read the docs and still cannot proceed to step 1 (or, is
> > that, step 0?).  I suspect it could also be used to
> > generate displays for a game such that one wouldn't need
> > a separate card for each location.
>
> But you could probably do the same with a delimited list as well. 
> Sometimes it's not bad to solve a problem with what you know, and 
> branch out in stages only as needed.
>
> > So, what I do is use a bunch of global variables to keep
> > track of these things (and, one card for every display).
> > I'm perhaps aware that this is not the best way to do such
> > things, but it is the way I CAN do such things.
>
> Getting results is rarely a bad place to start. :)
>
> It's hard for me to come up with a good example using your situation 
> without knowing more about it, but I'll give you one that helped me 
> understand some of the unique value of arrays.
>
> I had a circumstance where I needed to keep track of stuff globally 
> but couldn't know in advance how many of those things I would need so 
> I couldn't declare separate globals for each.
>
> I could have used a delimited list, but it would have looked something 
> like:
>
>   steve,100
>   bob,980
>   jane,444
>
> ...and it would have been cumbersome to write:
>
>   set the wholeMatches to true
>   get item 2 of lineOffset(tPerson,gMyGlobal)
>
> ...just to get that one value.
>
> Enter arrays:
>
> An array is just a collection of values in which each value has a 
> name.  That name can be a number or an alphanumeric string.  This 
> label is commonly called a "key", and if it helps I sometimes remind 
> myself that it's the key that unlocks the value.
>
> In the example above, we could store a value with something like:
>
>   put 100 into tMyArray["steve"]
>
> ...and get it with:
>
>   get tMyArray["steve"]

I have found that an array structure can be an excellent substitute for 
a long list of arrays. For example, in my project I declare a single 
global -- myGlobalArray. I then put things into it as needed. If I have 
set a particular numberformat, I put that into myGlobalArray, and 
retrieve it with "set the numberFormat to 
myGlobalArray["numberFormat"]".


>
> Conveniently, you don't need to keep track of what's in the list -- 
> you can get a list of keys like this:
>
>   get the keys of tMyArray
>
> ...which returns a return-delimited list of the labels of all of the 
> array elements.
>
> Even more convenient, you can store items in an array in one move by 
> using the split command.  If we had the delimited list above we could 
> tuck it into an array in one line:
>
>   put tMyList into tMyArray
>   combine tMyArray with return and comma
>
> The "with" part specifies the delimiters to be used for breaking the 
> text chunks into array elements.
>
> Since arrays are dependent on specific memory structures, they cannot 
> be easily stored directly.  You can't, for example, say "write 
> tMyArray to file whatever".  But you can use the combine command to 
> put an array into a chunk, effectively reversing the effect of the 
> split command:
>
>   put tMyArray into tMyList
>   combine tMyList with return and comma
>
> To delete an array element use the "delete variable" command:
>
>   delete variable tMyArray["steve"]
>
> You can also use variables to access array elements.  This example 
> will store a list of control names in an array by number:
>
>  repeat with i = 1 to the number of controls
>    put the short name of control i into tMyArray[i]
>  end repeat
>
>
> Play with those and post more questions as they come up.  I'm sure 
> others have as many questions about arrays as I did when Kevin and 
> Scott Raney patiently helped me through them on the MetaCard list way 
> back when.
>
> Sure beats linear algebra, eh? :)

Yep. But I have found myself going back to my linear algebra texts for 
help anyway.

Regards,

Raymond E. Griffith

>
> -- 
>  Richard Gaskin
>  Fourth World Media Corporation
>  ___________________________________________________
>  Rev tools and more:  http://www.fourthworld.com/rev
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>



More information about the use-livecode mailing list