[Coco] MC-10/CoCo BASIC - why did I code this way?
Johann Klasek
johann+coco at klasek.at
Fri Dec 29 09:18:56 EST 2017
Sorry, I'm comming late to the party ...
On Thu, Dec 28, 2017 at 01:26:32PM -0600, Allen Huffman wrote:
[..]
> But I see weird things in the code. I load up arrays manually, like this:
>
> 100 NM$(0)=???aaa???:NM$(1)=???xxx???:NM$(2)=???yyy???
[..]
> So why would I chose to do it manually? I assume this is a faster way to load the variables than READ/DATA, but I wonder if there was more.
I think it's just to save implementing a loop to fill up a small array.
> My thought:
>
> I knew strings could live in program code, or in string memory. Perhaps I did NOT know that strings could print IN to code, and assumed:
>
> 10 READ A$
> 20 DATA ???THIS IS A STRING???
>
> ...would result in ???THIS IS A STRING??? being in the program space, PLUS a copy in string memory.
No, this string is only a reference into the program code too (for
CB/ECB). To force that the string is in both areas you have to write
something like this:
100 A$="ABC"+""
The result of this expression will be placed into the string space (and a
death string in program space).
> That???s the only thing I can think of.
>
> Was there any other reason why someone would EVER manually load an array in BASIC like that? Seems awfully inefficient to me, now, and would have back then since I was well aware of READ/DATA.
There is probably a break even point on array elements for which the
initialization by assignments takes less in size than a loop with
READ/DATA. Maybe 3? I actually didn't go through the calculation ...
In the program of the above example, are there more assignment to the
NM$() array?
--
The dragon on my side: http://klasek.at/hc/dragon/
More information about the Coco
mailing list