Sunday, February 19, 2023

📚 About Comments: Samples

REM

For single line comment (as per any BASIC implementation)

REM This line will be ignored during program execution.

For multi-line comment

REM Sometimes, we want a comment _

    to span multiple lines.  The _

    "continuation" mark _

    (space followed by underscore) _

    is really good for this.

Single Quote    

' Although the single-quote is also an option for comments

' It is best for short comments, especially those that are added at the end of, and on the same line as, code.

PRINT "Hello World!"  ' The single quote is very convenient for this

PRINT "Hello World!" : REM We can use REM instead of a single quote, but it does require a colon to separate the "REM" statement from the previous statement

HTML Comment (Start and End tags)

<!-- BASIC Anywhere Machine being a browser-based implementation of BASIC,

     we can take advantage of the HTML way of adding comments if and when

     compatibility with other BASIC implementations is of no concern -->

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"}


🆕 Square brackets and curly brackets in complex expressions

(and simple expressions too !)

Up until today, and like other BASIC implementations, BASIC Anywhere Machine only allowed the use of parentheses in expressions.

Now, BASIC Anywhere Machine gives you the option to use square brackets (i.e. "[" and "]") and curly, I prefer "squiggly", brackets (i.e. "{" and "}") in expressions.

Using these in BASIC Anywhere Machine will result in an effort to replace those brackets with parentheses IF and WHEN porting BASIC Anywhere Machine programs to other BASIC implementations.

Some may find that mixing of brackets and parentheses confusing, especially when used to other BASIC implementations and/or when used to seeing brackets used in other programming languages and in a different context.

It is up to you to decide the pros, the cons, the cost/benefit.  You have the option if you like it.


Try it out: BASIC Anywhere Machine


Sunday, February 12, 2023

❇ Order of Numeric Operations 🆕 Negative Exponents

Order of Numeric Operations

Was:

  • Innermost operations between parentheses
  • Exponentiation
  • Negation
  • Multiplication, Division
  • Integer Division
  • Modulo
  • Addition and Subtraction

Now is:

  • Innermost operations between parentheses
  • Exponentiation
  • Negation
  • Multiplication, Division, Integer Division, Modulo
  • Addition and Subtraction


Negative Exponents

Negative exponents (for example: 5 ^ -2) would cause a program to abort with an error.

Now, BASIC Anywhere Machine knows how to handle negation of the exponent.





Thursday, February 9, 2023

🪲 New.BAS

New.BAS (A "Hello World!") program is a core component of BASIC Anywhere Machine.

It is the template for new programs.  (Some development tools would call it a "starter" program.)

The intention was for you to edit New.BAS such that that all of your new programs to be initially setup with whatever you want all of them to have when first created.

I just realised that I had hard-coded print "Hello world!" into the "new program" process.

OOPS!

Today's release of BASIC Anywhere Machine fixes that.  Now when you edit New.BAS with what you want new programs to start out with, your new programs will have what you want instead of "Hello world!".

Latest version of BASIC Anywhere Machine


Sunday, February 5, 2023

❇ CONST error messages on duplication and change of value

I wanted a better error messages for when:

  • a program attempts to declare a constant that already exists
  • a program attempts to alter the value of a constant





Saturday, February 4, 2023

❇ LET

The LET statement was implemented such that it could only handle one value-to-variable assignment.

Now, the LET statement allows multiple value-to-variable assignments.


For example:

LET a$ = "howdy",  b$ = "there"

Taking advantage of line continuation, and the LET keyword becomes useful as a visual marker indicating the declaration or variables and value assignments:

LET a$ = "howdy", _

    b$ = "there"


As was the case before, the LET keyword is optional (when declaring and assigning a value to one, and only one, variable.



Friday, February 3, 2023

🪲 File Open modal window: Search field

 The first time using the search field after opening BASIC Anywhere Machine, the first character typed was causing the focus to move away from the field.  To continue typing, we would have to put the focus on the field first.


I figured out the bug, and now the focus remains on the field while typing in it.




📚 FUNCTION (and SUB): variable arguments, by default, are "passed by reference"

Preamble A primer on "call-by-reference" vs "call-by-value" BAM HOWTO (BTW:  "call-by-reference" aka "pas...