r/Basic • • Aug 21 '22

BASIC and support for "metaprogramming"

Here's a a ridiculous example of something we can do in BASIC Anywhere Machine, and I wonder if this is something unique to BASIC Anywhere Machine or if it is something that can be done in any other BASIC dialects:

BASIC Anywhere Machine's interpreter currently knows nothing about PI.

In a "traditional" approach, we could define a constant for PI and use that constant throughout the program.

Here, I've instead embedded some TiddlyWiki syntax in the BASIC program, which TiddlyWiki processes (preprocessing phase?) just before passing the BASIC program to the interpreter.

During pre-processing, every occurence of <<pi>> will get replace by the literal value assigned to "pi" via the TiddlyWiki "$let" widget.

(In the image above, We see how the source gets manipulated by TiddlyWiki.)

I'm thinking this is pretty cool, kind of injecting an interesting twist to an old programming language. (Well, I'm not sure about the "readability" of the program for we human folk.)

I'm trying to cobble together some documentation for this. If you know of any good online references where I can find the right "lingo" for what I've shown here, please let me know.

Cheers !

11 Upvotes

9 comments sorted by

View all comments

Show parent comment

2

u/CharlieJV13 Aug 22 '22

A program is expanded every time when run in BASIC Anywhere Machine.

Expanded once when exported to .run.html (i.e. BASIC program and interpreter in a simple/small HTML file). So that a deployed program, still interpreted, is in a permanently expanded (i.e. "preprocessed") state.

Don't mind me: writing that and seeing it helps me remember it. I'm thinking BASIC Anywhere Machine, as a tool to learn/explore programming, can do some things that are lightly analogous to some pretty cool programming paradigms and C programming/Preprocessor directives and macros, and maybe some software development goodies.