Saturday, July 15, 2023

🆕 "Include Libraries" section in the Code Snippets tool

To make it much easier to include libraries of code, I've added an "Include Libraries" section to the "Code Snippets" tool.

The Include Libraries section provides automatically generated include directives for all programs tagged as "library" (in a program's File Properties.)

For any library you want to include in a program, just copy and paste into your program the include directive for the related library.

For example, the following screenshot shows the "PUTSTRING" include directive in the Code Snippets" tool, and how a copy/paste of that directive in a program looks:


By the way, this is what the File Properties looks like for the "PUTSTRING(x%, y%, s$)" library program:


Not that for BAM programs and libraries, the BAM and library tags cannot be unset.  For your programs, you'll have a check box for the library tag that looks like this:





📚 About the "{{Program Version Comment}}" Pre-Processor Directive

When you place {{Program Version Comment}} in your program, this will direct the BAM Pre-Processor to replace that snippet of text with a comment with the following information:

  • The version of BASIC Anywhere Machine used to export the program
  • The date and time of program export
Here's what the directive looks like in a program, and what the results look like when viewing the Pre-Processor code:




And, here's what the code looks like when exported:




Wednesday, July 12, 2023

🆕 PCOPY Statement and ✏ _RGB, _RGB32

Added the PCOPY statement.

The PCOPY statement is used to copy an entire graphics page, or a rectangular portion of a graphics page, to another.



About graphics pages in BASIC Anywhere Machine

BAM's support for pages is currently limited.  The three pages available:
      • 0
      • 1
      • 2
Page 0 is always the active page and is always the displayed page. All screen output statements (PRINT and all graphics statements) are processed on page 0.


Modified the _RGB and _RGB32 functions


The functions  would misbehave when passed floating-point values in any of their arguments, in some circumstances requiring INT be explicitly applied to every argument.

Now, BAM implicitly (with INT) takes care of converting any floating point parameter values to integers.  So you no longer need to apply INT to your function parameters.









Friday, July 7, 2023

💡 How to (quickly) temporarily comment out large blocks of code

We can certainly comment out code with either the REM statement or a single-quote.  That gets tedious when we have many lines of code in a block we wish to comment out.

Instead, we can make use of a "pre-processor" directive (or "macro-programming") to exclude, at run-time and on export, any and all code between

  • a <!-- opening tag
  • and a --> closing tag

NOTE: BASIC comments with REM statements and single-quotes remain part of the program.  They are not excluded at either runtime (their, they are ignored) or on export.

Here's a short program with some code commented out, and the results of running that program:


Just to make the leading and trailing tags jump out more, I like to make use of some jugular-grabbing emojis.  You might find it useful to also add a little note to remind you why the code is commented out, and remind you to uncomment that code later.


Do keep in mind, though: When there are errors in a program, BAM references the line number (as in the line at which the code is located vis-à-vis the first line of the program AT RUNTIME (or upon export), as in after the code has been altered by the preprocessor.

For example, here's an error in the 6th line of the program (using the editor's line numbers), versus the line with the error at runtime:


How to find in the program what the interpreter is flagging as line 3?  Figure out what code is causing the problem by Viewing the preprocess code (Project Menu and "View Preprocess Code") for whichever version of the program you ran.


Notice that the lines of code that got commented out were replaced by a blank line.  We can see the error is a mispelled print statement, and we can use that to scan/search our program and fix the problem.


Try it out for yourself !


Another use case: to add comments to your program that will be excluded when you export the program for sharing !


Thursday, July 6, 2023

💡 Making the case for GOTO use cases

It didn't take long for me to be a "never GOTO, never ever" guy once we started to see structured BASIC implementations displace unstructured BASIC implementations.

Since I started working on BASIC Anywhere Machine back in December 2020, I've really come to appreciate the use of GOTO with line labels (instead of line numbers) in a couple of scenarios.

BASIC Anywhere Machine (aka "BAM") links:

 

Always being weary, of course, of not creating spaghetti code, here are two scenarios in which I find GOTO really practical.  When do you find GOTO useful and acceptable ?

Loops involving a lot of code

For the following blocks of code:

  • WHILE ... WEND 
  • WHILE ... LOOP
  • DO ... LOOP
  • DO WHILE ... LOOP
  • DO WHILE ... WEND
  • DO LOOP ... WHILE
  • DO LOOP ... UNTIL
If the bookends of the code block are so far apart that screen scrolling becomes necessary to see all of the code in the block, or if the code block had nested loops, matching the right bookends can become challenging.

I often prefer GOTO in these circumstances (expecially an infinite DO ... LOOP) because line labels make it easy to match the bookends of a code block.

For example:

StartLoop1: ...
...
...
GOTO StartLoop1

I find this approach concise and descriptive.


Skip over a block of code

In some circumstances, it makes more sense to me to have an IF that skips a block of code, rather than have an IF condition be satisfied to execute that block of code (and exclude the block otherwise).

Step1:
IF condition GOTO Step2
...
...
Step2:




Tuesday, July 4, 2023

📚 IF syntax documentation in progress

IF single-line conditional branch:


IF multi-statement single line


IF single-line single-statement alternatives


IF multi-line multi-alternatives code blocks


codeBlockForCondition







🆕 Tags (to describe and find programs) and ✏ New program defaults

Program Tags

Go to the File menu and click on Properties.


The "Tags" section is new.  For a selected program, click on any available check boxes to associate the program with that tag.


  Enter a new tag in the field, then press the "Create" button.  The tag will be added to the list and automatically selected.


Once any one program is tagged with some value, that tag becomes available to select for all other programs.


New feature on the "File Open" dialog: tags can be used to find programs that have all of the selected tags.


New Program Defaults now allows setting a "comprehensive" list of defaults that will be applied to new programs.


Note that this edits the program execution properties of the "New.BAS" program.  Every new program created in BAM starts off as a copy of "New.BAS".


For example, after creating a new program, here are the Program Execution Properties:



🖥 Circular Sinusoidal Waves with DRAW and SIN

Run the program View the source code