Saturday, March 15, 2025

📚 Simulating OOP Methods in BAM Using GOSUB

BASIC Anywhere Machine's GOSUB implementation allows using numeric expressions for dynamic line numbers or using string expressions for dynamic line labels.

  • As of this blog entry's publishing,  the "production" version of BAM requires such an expression to be within parentheses and preceded by the "EVAL" keyword
    • example:  GOSUB EVAL( some_expression )
  • The current "development" version of BAM drops the "EVAL" keyword, because the parentheses are enough for indicating an expression for GOSUB
    • example:  GOSUB ( some_expression )
    • note: this syntax will appear in some yet-to-be-determined "production" release of BAM, replacing the syntax using "EVAL"
The use of expressions as GOSUB arguments allows BAM programs to simulate OOP methods, as demonstrated in the following program:
The program fills the screen with 570 random shapes (circles or squares) with random ( x, y ) center coordinates, random colours, and random sizes.

Each type of shape has a dedicated shape-drawing GOSUB routine.

The program is written in a way that assumes a future enhancement that involves movement of the shapes and bouncing away from the edges of the screen.

No comments:

Post a Comment

📚 Simulating OOP Methods in BAM Using GOSUB

BASIC Anywhere Machine's GOSUB implementation allows using numeric expressions for dynamic line numbers or using string expressions for ...