Shop OBEX P1 Docs P2 Docs Learn Events
array reference on non-array — Parallax Forums

array reference on non-array

DonDon Posts: 34
edited 2004-08-09 19:19 in BASIC Stamp
I noticed that if I create a non-array variable, the tokenizer doesn't complain if·I reference it using a subscript.· For example,

i VAR Byte
...
i(1) = 3



I see no mention of this "feature" in the manual.· The manual does mention, however, that the first element of an array may be referenced without using the subscript.· I assume that these are two sides of the same coin.

Also, I see that the set of operators that can be used in constant expressions is fairly limited.· Being able to use SIN or DCD in a constant expression would be handy and would seem to be a fairly trivial extension of the tokenizer code.




▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don Kinzer

·

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-09 19:19
    You're right, we may not have covered the array feature in the manual, though I think the update does hit on it (I worked on that a long time ago, so I don't remember). What you've discovered (and that many of us take advantage of) is that the entire RAM space may be treated as an array. The type will depend on your base variable. You could, for example, see the entire RAM space as an array of bits -- a bunch of bits.

    I use this strategy with aliasing to keep my code easy to read. Here's one example:

    red···· VAR· Byte
    green·· VAR· Byte

    blue··· VAR· Byte
    colors· VAR· red
    idx···· VAR· Nib

    Now I can initialize all three colors to any value like this:

    FOR idx = 0 TO 2
    ·· colors(idx) = 0
    NEXT

    I don't know that we'll ever be able to add functions like SIN and DCD to constant declarations, but I will pass the suggestion on to our Engineering department.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 8/9/2004 7:23:41 PM GMT
Sign In or Register to comment.