Shop OBEX P1 Docs P2 Docs Learn Events
Array — Parallax Forums

Array

Old TimerOld Timer Posts: 3
edited 2008-03-04 06:24 in Propeller 1
New to Spin. I haven't been able to find any mention of this. Does spin provide for multi dimension arrays or lists? For example, how can I set up an indexed·list or array of x/y coordinates in Spin without using a string· or concatanated series of integers, which would then need to be parsed?

Thanks,

BobA

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-03-04 01:57
    There is no direct support multi-dimensional arrays, though data[noparse][[/noparse]x + y * DIMX] works just fine. (DIMX is a constant equal to the number of elements in the X direction).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Old TimerOld Timer Posts: 3
    edited 2008-03-04 04:54
    Thanks for the quick reply Paul. I don't understand what·you mean with that equation as it applies to my question. Unless I'm missing your point, if I want to set up an indexed·list of "stops" using a grid and coordinates that describe a path for a robot to traverse with one dimentional arrays, I either need to parse·elements·or use multiple synchronized arrays (which is less than ideal). What am I not seeing?

    Thanks again,



    BobA
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-04 06:09
    What you're not seeing is that Paul was describing how multidimensional arrays are actually implemented in most languages. Memory is only one dimensional. If you have a 4 x 5 array, the compiler will group 4 elements for the X subscripts for a given Y subscript value and repeat that 5 times. In calculating the location in memory, you have to multiply the Y value by the dimension of X (4 in this case) to get X + Y * DimX which is the offset in memory of the array element. Obviously, if the dimensions start at anything other than zero, you have to adjust X and Y appropriately.
  • Old TimerOld Timer Posts: 3
    edited 2008-03-04 06:24
    AHA! Thank you, Mike,
Sign In or Register to comment.