[Coco] What are the rules for naming basic09 variables ?

Wayne Campbell asa.rand at gmail.com
Sun Jul 28 20:32:57 EDT 2019


I looked at the Basic09 manuals (level 1 & 2) and I am mistaken about it
saying anything about variable name length. This validated what James said
about the code, and what Curtis said. I doubt anyone would want a variable
name long enough to use all available memory in the workspace, but you can
do it.

On Sat, Jul 27, 2019, 8:06 PM Wayne Campbell <asa.rand at gmail.com> wrote:

> Ok. That makes sense. As for the symbol table, in packed i-code, it is a
> list of 3-byte entries. The first byte is the variable type, and the
> integer is the memory offset where that variable's contents are stored.
> This is the simple description. It is more involved when you get into it.
> The cocopedia page I created has all the info on what the various values
> are.
>
> On Sat, Jul 27, 2019, 7:58 PM James Jones <jejones3141 at gmail.com> wrote:
>
>> The relevant code starts, I believe, at L2430 in basic09_6809.listing. It
>> accepts a letter followed by some number of alphanumerics or underscores,
>> optionally with a $ at the end as the string sigil. The loop doesn't
>> itself
>> bound the length of the variable name, though there's also the matter of
>> the size of the buffer used to read lines of source code, which would also
>> bound the maximum variable name length. Further down, though, is
>>
>> L2459  stb <NAMELEN    Save size of variable name
>>
>> so that a variable name length greater than 255 won't fit in the B
>> register
>> and the wrong value will be stored in <NAMELEN.
>>
>> The other thing that may bound the length of a variable name is: what does
>> the symbol table look like? The first time you see a variable or parameter
>> mentioned, you have to save its name; the lexical scanner code is looking
>> through a buffer that I suspect only exists while you're loading or
>> editing
>> a source file. Depending on how the symbol table is set up, it might have
>> a
>> fixed limit on variable name length. (I haven't gone looking for the
>> symbol
>> table yet.)
>>
>> That said--all that really matters is:
>>
>>    - The maximum length, if it exists, is considerably greater than two,
>> so
>>    in BASIC09 you can have intelligible variable names without coming
>> anywhere
>>    close to the maximum length, if it exists..
>>    - Variable names don't appear in I-code as such, so executing BASIC09
>>    code doesn't involve looking up variable names, and as others have
>> pointed
>>    out, they don't take up space in packed I-code modules.
>>    - You'll notice that a variable or parameter name will always show up
>> in
>>    a listing with the case you used the first time BASIC09 saw it. This, I
>>    believe, implies that BASIC09 only keeps one copy of each variable or
>>    parameter name (the one in the symbol table) around, so even in
>> BASIC09,
>>    the space overhead of variable names is minimized. Also, IMHO, it
>> tilts the
>>    balance towards using camelCase rather than snake_case. Type names the
>> way
>>    you want them the first time, and thereafter you needn't hit the shift
>> key.
>>    BASIC09 will do the work for you, and you don't have underscores
>> taking up
>>    room.
>>
>> --
>> Coco mailing list
>> Coco at maltedmedia.com
>> https://pairlist5.pair.net/mailman/listinfo/coco
>>
>


More information about the Coco mailing list