PDA

View Full Version : Array questions


jrrTolkien
07-18-2014, 09:53 AM
I've used arrays in a few programming languages before, but I don't really understand how they work in Alice. And what's the difference between lists and arrays? And what are 1-dimensional arrays in Alice? I know what they are in some other programming languages, but not a 3-D one like this...

-jrr

MrMoke
07-18-2014, 02:37 PM
Welcome Back JRR-
Arrays are pretty much the same in all programming languages. They are fixed length constructs of items that all have to be the same type. In older languages that meant all characters, integers, or Floating point values. In newer languages that definition has been expanded, but the rules are the same.
An array has a predefined length, which cannot be changed. Each item can be accessed and/or replaced by assigning a specific value to the array's index pointer, then manipulating the referenced memory location. Accessing and/or storing information from multiple same-size arrays with the same index value, has been used for a long time in programming.

A one-dimensional array, like those in Alice, might hold something like all the integers from 0 to 9.

A two-dimensional array, which could be visualized as a box, might contain something like all of the pixels on your monitor, so accessing monitor(x,y) might access the pixel in row x, col y, or vice-versa depending how the programmer set it up.

A three-dimensional array could hold all the data points in an Alice World.

Any arrays larger than that makes my head hurt because it involves time travel :eek:

Lists look the same, and can be accessed in the same manner, but are somewhat more pliable in that the length is not fixed once they have been created. You can add, modify, and delete items from any position. Because of this, the length of a list can vary from moment to moment, so care must be taken when trying to use then the same way as an array.

In Alice, lists are given special attention when using commands like "For All Together", "For All In Order", etc.

jrrTolkien
07-21-2014, 07:54 PM
I actually didn't leave, the forum just has been pretty quiet and I didn't have anything to ask before. :) Anyway, thanks for your answer!

-Jrr