Tuesday, March 28, 2023

⛯ Making sure your program gets the "focus"

 A BASIC Anywhere Machine program cannot receive keyboard input (nor produce any audio) if it does not have the "focus".

For any program that's going to need (physical) keyboard input and/or produce audio output, it is a good idea for the program to get the focus just before the first line of code gets executed.

To have the program pause until it gets the focus, you have to turn off the "autostart this program" feature (which is set to "on" by default).

In the "Project" menu, click on the "Runtime Properties ..." menu item.

That will open the "Runtime Properties Viewer" window.

Remove the check mark on "Autostart his program".



Saturday, March 25, 2023

📚 "What is Computer Programming?" starts with "What is a Computer?"

Many old BASIC programming books define "Computer" very early as part of describing programming and the BASIC programming language.

I think it is worth thinking of programming and programming languages in a broader context.

What do you think?

Take a look at the beginning of the topic What is Computer Programming? and expand the first cut of the section "What is a computer?"

Friday, March 24, 2023

🆕 Programming Reference: feature to try your own code next to code snippets

The best kind of documentation is the kind that not only allows you to run example code, but also let's you try your own code !!!

Update: I'm in the process of changing the navigation setup in the documentation, so the previous example doesn't work right now.

This new example, although a work in progress, will work going forward with the bonus of describing the wonderfulness of running example code (and trying your own code) right "there", where your focus happens to be.  Click on the following link to see and try for yourself:


Saturday, March 11, 2023

🆕 _MAPSET and _MAPGET

 From Wikipedia:

A name–value pair, also called an attribute–value pair, key–value pair, or field–value pair, is a fundamental data representation in computing systems and applications. Designers often desire an open-ended data structure that allows for future extension without modifying existing code or data. In such situations, all or part of the data model may be expressed as a collection of 2-tuples in the form <attribute name, value> with each element being an attribute–value pair. Depending on the particular application and the implementation chosen by programmers, attribute names may or may not be unique.


BASIC Anywhere Machine provides a global "MAP" object for holding key-value pairs W. Each key is a unique string value to which is related some value (numeric or string) that can be repeated for other keys.

_MAPSET

Description:

The _MAPSET statement stores the value (a number or a string which may be the result of an expression) for the provided key (which may be the result of an expression.)

Syntax

_MAPSET( strExprKey, exprValue )

  • strExprKey
    • a string, which may be a literal value, a constant, a variable, or an expression of whatever complexity
  • exprValue
    • a number or a string, which may be a literal value, a constant, a variable, or an expression of whatever complexity


_MAPGET

Description:

The _MAPGET function retrieves the value for the provided key (which may be an expression resulting in a key.)

Syntax

_MAPGET( strExprKey )

  • returns: the value associated with the key (numeric or string)
    • however, if there is no matching key, then the return value is an empty string (i.e. "")



Friday, March 3, 2023

🆕 "?" as shorthand for PRINT

Can any BASIC implementation really be a BASIC without the ability to use "?" as an alternative to the keyword "PRINT" ?

One of my goals includes the ability too easily, with few if not zero edits, get old BASIC programs running in BASIC Anywhere Machine.

The ability to recognise "?" as meaning "PRINT" not only helps in that goal, but also feels good for anybody who did any BASIC programming during the home computer revolution.


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


🖥 Geometric Mandalas

As a coding exercise, I wanted to make use of DRAW statements to get plot points for regular polygons repeated around an axis to create geom...