Tuesday, February 14, 2023

For one dimension arrays: 🆕 Array initialisation 🆕 Constant Arrays

Current version of BASIC Anywhere Machine.

BASIC Anywhere Machine's interpreter is a substantially enhanced and altered version of wwwBASIC.

To keep BASIC Anywhere Machine as a single-file TiddlyWiki instance with no external dependencies, the "stock" version of wwwBASIC.js (circa December 2021) was embedded in BASIC Anywhere Machine and enhanced right there.

Array Initialisation

I had not noticed that wwwBASIC has provided all along the ability to initialise one-dimension arrays with values upon declaration.  The related syntax by example:

DIM DAY$(1 to 7) = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}

Or, if you prefer not using data type suffixes, and if you want to use (something else I recently discovered was already built-in) line continuation (space and underscore at the end of the line):

DIM as string Day(1 to 7) _

              = {"Monday", _

                 "Tuesday", _

                 "Wednesday", _

                 "Thursday", _

                 "Friday", _

                 "Saturday", _

                 "Sunday"}


Constant Arrays

For whatever reason, as soon as I saw this ability, I thought: "hey, it would be cool if we could use this for constant arrays.  So I rolled-up my sleeves and set it up.  Same syntax options, the only difference involves  for replacing the "DIM" keyword with the "CONST" keyword, and then BASIC Anywhere Machine will give an error when any attempt is made to alter an element in the array.

CONST DAY$(1 to 7) = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday", "Sunday"}

or:

CONST as string Day(1 to 7) _

              = {"Monday", _

                 "Tuesday", _

                 "Wednesday", _

                 "Thursday", _

                 "Friday", _

                 "Saturday", _

                 "Sunday"}


No comments:

Post a Comment

🖥 Flower Tesselation: Testing DRAW and recursive SUB's

This BAM program inspired by Richard Russell's "Flower-like tesselation" BBC BASIC program posted on Facebook . Created in ord...